From f2ee759ad56a11ee42236b13d7edf687149b7d94 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 15 Apr 2016 11:51:47 +0200 Subject: [PATCH 01/87] Upgrade AWS SDK to 1.10.69 * Moving from JSON.org to Jackson for request marshallers. * The Java SDK now supports retry throttling to limit the rate of retries during periods of reduced availability. This throttling behavior can be enabled via ClientConfiguration or via the system property "-Dcom.amazonaws.sdk.enableThrottledRetry". * Fixed String case conversion issues when running with non English locales. * AWS SDK for Java introduces a new dynamic endpoint system that can compute endpoints for services in new regions. * Introducing a new AWS region, ap-northeast-2. * Added a new metric, HttpSocketReadTime, that records socket read latency. You can enable this metric by adding enableHttpSocketReadMetric to the system property com.amazonaws.sdk.enableDefaultMetrics. For more information, see [Enabling Metrics with the AWS SDK for Java](https://java.awsblog.com/post/Tx3C0RV4NRRBKTG/Enabling-Metrics-with-the-AWS-SDK-for-Java). * New Client Execution timeout feature to set a limit spent across retries, backoffs, ummarshalling, etc. This new timeout can be specified at the client level or per request. Also included in this release is the ability to specify the existing HTTP Request timeout per request rather than just per client. * Added support for RequesterPays for all operations. * Ignore the 'Connection' header when generating S3 responses. * Allow users to generate an AmazonS3URI from a string without using URL encoding. * Fixed issue that prevented creating buckets when using a client configured for the s3-external-1 endpoint. * Amazon S3 bucket lifecycle configuration supports two new features: the removal of expired object delete markers and an action to abort incomplete multipart uploads. * Allow TransferManagerConfiguration to accept integer values for multipart upload threshold. * Copy the list of ETags before sorting https://github.com/aws/aws-sdk-java/pull/589. * Option to disable chunked encoding https://github.com/aws/aws-sdk-java/pull/586. * Adding retry on InternalErrors in CompleteMultipartUpload operation. https://github.com/aws/aws-sdk-java/issues/538 * Deprecated two APIs : AmazonS3#changeObjectStorageClass and AmazonS3#setObjectRedirectLocation. * Added support for the aws-exec-read canned ACL. Owner gets FULL_CONTROL. Amazon EC2 gets READ access to GET an Amazon Machine Image (AMI) bundle from Amazon S3. * Added support for referencing security groups in peered Virtual Private Clouds (VPCs). For more information see the service announcement at https://aws.amazon.com/about-aws/whats-new/2016/03/announcing-support-for-security-group-references-in-a-peered-vpc/ . * Fixed a bug in AWS SDK for Java - Amazon EC2 module that returns NPE for dry run requests. * Regenerated client with new implementation of code generator. * This feature enables support for DNS resolution of public hostnames to private IP addresses when queried over ClassicLink. Additionally, you can now access private hosted zones associated with your VPC from a linked EC2-Classic instance. ClassicLink DNS support makes it easier for EC2-Classic instances to communicate with VPC resources using public DNS hostnames. * You can now use Network Address Translation (NAT) Gateway, a highly available AWS managed service that makes it easy to connect to the Internet from instances within a private subnet in an AWS Virtual Private Cloud (VPC). Previously, you needed to launch a NAT instance to enable NAT for instances in a private subnet. Amazon VPC NAT Gateway is available in the US East (N. Virginia), US West (Oregon), US West (N. California), EU (Ireland), Asia Pacific (Tokyo), Asia Pacific (Singapore), and Asia Pacific (Sydney) regions. To learn more about Amazon VPC NAT, see [New - Managed NAT (Network Address Translation) Gateway for AWS](https://aws.amazon.com/blogs/aws/new-managed-nat-network-address-translation-gateway-for-aws/) * A default read timeout is now applied when querying data from EC2 metadata service. --- plugins/discovery-ec2/build.gradle | 7 +- .../aws-java-sdk-core-1.10.33.jar.sha1 | 1 - .../aws-java-sdk-core-1.10.69.jar.sha1 | 1 + .../aws-java-sdk-ec2-1.10.33.jar.sha1 | 1 - .../aws-java-sdk-ec2-1.10.69.jar.sha1 | 1 + .../discovery/ec2/AmazonEC2Mock.java | 128 ++++++++++++++++++ plugins/repository-s3/build.gradle | 10 +- .../aws-java-sdk-core-1.10.33.jar.sha1 | 1 - .../aws-java-sdk-core-1.10.69.jar.sha1 | 1 + .../aws-java-sdk-kms-1.10.33.jar.sha1 | 1 - .../aws-java-sdk-kms-1.10.69.jar.sha1 | 1 + .../licenses/aws-java-sdk-s3-1.10.33.jar.sha1 | 1 - .../licenses/aws-java-sdk-s3-1.10.69.jar.sha1 | 1 + .../cloud/aws/AmazonS3Wrapper.java | 18 +++ 14 files changed, 156 insertions(+), 17 deletions(-) delete mode 100644 plugins/discovery-ec2/licenses/aws-java-sdk-core-1.10.33.jar.sha1 create mode 100644 plugins/discovery-ec2/licenses/aws-java-sdk-core-1.10.69.jar.sha1 delete mode 100644 plugins/discovery-ec2/licenses/aws-java-sdk-ec2-1.10.33.jar.sha1 create mode 100644 plugins/discovery-ec2/licenses/aws-java-sdk-ec2-1.10.69.jar.sha1 delete mode 100644 plugins/repository-s3/licenses/aws-java-sdk-core-1.10.33.jar.sha1 create mode 100644 plugins/repository-s3/licenses/aws-java-sdk-core-1.10.69.jar.sha1 delete mode 100644 plugins/repository-s3/licenses/aws-java-sdk-kms-1.10.33.jar.sha1 create mode 100644 plugins/repository-s3/licenses/aws-java-sdk-kms-1.10.69.jar.sha1 delete mode 100644 plugins/repository-s3/licenses/aws-java-sdk-s3-1.10.33.jar.sha1 create mode 100644 plugins/repository-s3/licenses/aws-java-sdk-s3-1.10.69.jar.sha1 diff --git a/plugins/discovery-ec2/build.gradle b/plugins/discovery-ec2/build.gradle index e8baa1ec502..15cce1aa32b 100644 --- a/plugins/discovery-ec2/build.gradle +++ b/plugins/discovery-ec2/build.gradle @@ -23,7 +23,7 @@ esplugin { } versions << [ - 'aws': '1.10.33' + 'aws': '1.10.69' ] dependencies { @@ -48,11 +48,6 @@ test { } thirdPartyAudit.excludes = [ - // uses internal java api: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl - // uses internal java api: com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefault - // uses internal java api: com.sun.org.apache.xpath.internal.XPathContext - 'com.amazonaws.util.XpathUtils', - // classes are missing 'javax.servlet.ServletContextEvent', 'javax.servlet.ServletContextListener', diff --git a/plugins/discovery-ec2/licenses/aws-java-sdk-core-1.10.33.jar.sha1 b/plugins/discovery-ec2/licenses/aws-java-sdk-core-1.10.33.jar.sha1 deleted file mode 100644 index 332a8f01035..00000000000 --- a/plugins/discovery-ec2/licenses/aws-java-sdk-core-1.10.33.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -fabedbbe2b834b1add150b6a38395c5ef7380168 \ No newline at end of file diff --git a/plugins/discovery-ec2/licenses/aws-java-sdk-core-1.10.69.jar.sha1 b/plugins/discovery-ec2/licenses/aws-java-sdk-core-1.10.69.jar.sha1 new file mode 100644 index 00000000000..2971a33d7d9 --- /dev/null +++ b/plugins/discovery-ec2/licenses/aws-java-sdk-core-1.10.69.jar.sha1 @@ -0,0 +1 @@ +a1f02d5f26ba1d8c37e2bf9c847db3c6729dda00 \ No newline at end of file diff --git a/plugins/discovery-ec2/licenses/aws-java-sdk-ec2-1.10.33.jar.sha1 b/plugins/discovery-ec2/licenses/aws-java-sdk-ec2-1.10.33.jar.sha1 deleted file mode 100644 index 4737b80b3f2..00000000000 --- a/plugins/discovery-ec2/licenses/aws-java-sdk-ec2-1.10.33.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -202f6b5dbc196e355d50c131b0fd34969bfd89e6 \ No newline at end of file diff --git a/plugins/discovery-ec2/licenses/aws-java-sdk-ec2-1.10.69.jar.sha1 b/plugins/discovery-ec2/licenses/aws-java-sdk-ec2-1.10.69.jar.sha1 new file mode 100644 index 00000000000..a1a493d3b8f --- /dev/null +++ b/plugins/discovery-ec2/licenses/aws-java-sdk-ec2-1.10.69.jar.sha1 @@ -0,0 +1 @@ +afbff1ece8365859eb4cfe0d3ba543d68b154d26 \ No newline at end of file diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AmazonEC2Mock.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AmazonEC2Mock.java index 88d87a2d8c2..881cb98e1d1 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AmazonEC2Mock.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AmazonEC2Mock.java @@ -29,6 +29,8 @@ import com.amazonaws.services.ec2.model.AcceptVpcPeeringConnectionRequest; import com.amazonaws.services.ec2.model.AcceptVpcPeeringConnectionResult; import com.amazonaws.services.ec2.model.AllocateAddressRequest; import com.amazonaws.services.ec2.model.AllocateAddressResult; +import com.amazonaws.services.ec2.model.AllocateHostsRequest; +import com.amazonaws.services.ec2.model.AllocateHostsResult; import com.amazonaws.services.ec2.model.AssignPrivateIpAddressesRequest; import com.amazonaws.services.ec2.model.AssociateAddressRequest; import com.amazonaws.services.ec2.model.AssociateAddressResult; @@ -80,6 +82,8 @@ import com.amazonaws.services.ec2.model.CreateInternetGatewayRequest; import com.amazonaws.services.ec2.model.CreateInternetGatewayResult; import com.amazonaws.services.ec2.model.CreateKeyPairRequest; import com.amazonaws.services.ec2.model.CreateKeyPairResult; +import com.amazonaws.services.ec2.model.CreateNatGatewayRequest; +import com.amazonaws.services.ec2.model.CreateNatGatewayResult; import com.amazonaws.services.ec2.model.CreateNetworkAclEntryRequest; import com.amazonaws.services.ec2.model.CreateNetworkAclRequest; import com.amazonaws.services.ec2.model.CreateNetworkAclResult; @@ -120,6 +124,8 @@ import com.amazonaws.services.ec2.model.DeleteFlowLogsRequest; import com.amazonaws.services.ec2.model.DeleteFlowLogsResult; import com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest; import com.amazonaws.services.ec2.model.DeleteKeyPairRequest; +import com.amazonaws.services.ec2.model.DeleteNatGatewayRequest; +import com.amazonaws.services.ec2.model.DeleteNatGatewayResult; import com.amazonaws.services.ec2.model.DeleteNetworkAclEntryRequest; import com.amazonaws.services.ec2.model.DeleteNetworkAclRequest; import com.amazonaws.services.ec2.model.DeleteNetworkInterfaceRequest; @@ -161,6 +167,10 @@ import com.amazonaws.services.ec2.model.DescribeExportTasksRequest; import com.amazonaws.services.ec2.model.DescribeExportTasksResult; import com.amazonaws.services.ec2.model.DescribeFlowLogsRequest; import com.amazonaws.services.ec2.model.DescribeFlowLogsResult; +import com.amazonaws.services.ec2.model.DescribeHostsRequest; +import com.amazonaws.services.ec2.model.DescribeHostsResult; +import com.amazonaws.services.ec2.model.DescribeIdFormatRequest; +import com.amazonaws.services.ec2.model.DescribeIdFormatResult; import com.amazonaws.services.ec2.model.DescribeImageAttributeRequest; import com.amazonaws.services.ec2.model.DescribeImageAttributeResult; import com.amazonaws.services.ec2.model.DescribeImagesRequest; @@ -181,6 +191,8 @@ import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; import com.amazonaws.services.ec2.model.DescribeKeyPairsResult; import com.amazonaws.services.ec2.model.DescribeMovingAddressesRequest; import com.amazonaws.services.ec2.model.DescribeMovingAddressesResult; +import com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest; +import com.amazonaws.services.ec2.model.DescribeNatGatewaysResult; import com.amazonaws.services.ec2.model.DescribeNetworkAclsRequest; import com.amazonaws.services.ec2.model.DescribeNetworkAclsResult; import com.amazonaws.services.ec2.model.DescribeNetworkInterfaceAttributeRequest; @@ -203,6 +215,10 @@ import com.amazonaws.services.ec2.model.DescribeReservedInstancesRequest; import com.amazonaws.services.ec2.model.DescribeReservedInstancesResult; import com.amazonaws.services.ec2.model.DescribeRouteTablesRequest; import com.amazonaws.services.ec2.model.DescribeRouteTablesResult; +import com.amazonaws.services.ec2.model.DescribeScheduledInstanceAvailabilityRequest; +import com.amazonaws.services.ec2.model.DescribeScheduledInstanceAvailabilityResult; +import com.amazonaws.services.ec2.model.DescribeScheduledInstancesRequest; +import com.amazonaws.services.ec2.model.DescribeScheduledInstancesResult; import com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest; import com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult; import com.amazonaws.services.ec2.model.DescribeSnapshotAttributeRequest; @@ -233,6 +249,8 @@ import com.amazonaws.services.ec2.model.DescribeVolumesRequest; import com.amazonaws.services.ec2.model.DescribeVolumesResult; import com.amazonaws.services.ec2.model.DescribeVpcAttributeRequest; import com.amazonaws.services.ec2.model.DescribeVpcAttributeResult; +import com.amazonaws.services.ec2.model.DescribeVpcClassicLinkDnsSupportRequest; +import com.amazonaws.services.ec2.model.DescribeVpcClassicLinkDnsSupportResult; import com.amazonaws.services.ec2.model.DescribeVpcClassicLinkRequest; import com.amazonaws.services.ec2.model.DescribeVpcClassicLinkResult; import com.amazonaws.services.ec2.model.DescribeVpcEndpointServicesRequest; @@ -255,6 +273,8 @@ import com.amazonaws.services.ec2.model.DetachVolumeRequest; import com.amazonaws.services.ec2.model.DetachVolumeResult; import com.amazonaws.services.ec2.model.DetachVpnGatewayRequest; import com.amazonaws.services.ec2.model.DisableVgwRoutePropagationRequest; +import com.amazonaws.services.ec2.model.DisableVpcClassicLinkDnsSupportRequest; +import com.amazonaws.services.ec2.model.DisableVpcClassicLinkDnsSupportResult; import com.amazonaws.services.ec2.model.DisableVpcClassicLinkRequest; import com.amazonaws.services.ec2.model.DisableVpcClassicLinkResult; import com.amazonaws.services.ec2.model.DisassociateAddressRequest; @@ -263,6 +283,8 @@ import com.amazonaws.services.ec2.model.DryRunResult; import com.amazonaws.services.ec2.model.DryRunSupportedRequest; import com.amazonaws.services.ec2.model.EnableVgwRoutePropagationRequest; import com.amazonaws.services.ec2.model.EnableVolumeIORequest; +import com.amazonaws.services.ec2.model.EnableVpcClassicLinkDnsSupportRequest; +import com.amazonaws.services.ec2.model.EnableVpcClassicLinkDnsSupportResult; import com.amazonaws.services.ec2.model.EnableVpcClassicLinkRequest; import com.amazonaws.services.ec2.model.EnableVpcClassicLinkResult; import com.amazonaws.services.ec2.model.Filter; @@ -283,8 +305,13 @@ import com.amazonaws.services.ec2.model.ImportVolumeResult; import com.amazonaws.services.ec2.model.Instance; import com.amazonaws.services.ec2.model.InstanceState; import com.amazonaws.services.ec2.model.InstanceStateName; +import com.amazonaws.services.ec2.model.ModifyHostsRequest; +import com.amazonaws.services.ec2.model.ModifyHostsResult; +import com.amazonaws.services.ec2.model.ModifyIdFormatRequest; import com.amazonaws.services.ec2.model.ModifyImageAttributeRequest; import com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest; +import com.amazonaws.services.ec2.model.ModifyInstancePlacementRequest; +import com.amazonaws.services.ec2.model.ModifyInstancePlacementResult; import com.amazonaws.services.ec2.model.ModifyNetworkInterfaceAttributeRequest; import com.amazonaws.services.ec2.model.ModifyReservedInstancesRequest; import com.amazonaws.services.ec2.model.ModifyReservedInstancesResult; @@ -302,12 +329,16 @@ import com.amazonaws.services.ec2.model.MoveAddressToVpcRequest; import com.amazonaws.services.ec2.model.MoveAddressToVpcResult; import com.amazonaws.services.ec2.model.PurchaseReservedInstancesOfferingRequest; import com.amazonaws.services.ec2.model.PurchaseReservedInstancesOfferingResult; +import com.amazonaws.services.ec2.model.PurchaseScheduledInstancesRequest; +import com.amazonaws.services.ec2.model.PurchaseScheduledInstancesResult; import com.amazonaws.services.ec2.model.RebootInstancesRequest; import com.amazonaws.services.ec2.model.RegisterImageRequest; import com.amazonaws.services.ec2.model.RegisterImageResult; import com.amazonaws.services.ec2.model.RejectVpcPeeringConnectionRequest; import com.amazonaws.services.ec2.model.RejectVpcPeeringConnectionResult; import com.amazonaws.services.ec2.model.ReleaseAddressRequest; +import com.amazonaws.services.ec2.model.ReleaseHostsRequest; +import com.amazonaws.services.ec2.model.ReleaseHostsResult; import com.amazonaws.services.ec2.model.ReplaceNetworkAclAssociationRequest; import com.amazonaws.services.ec2.model.ReplaceNetworkAclAssociationResult; import com.amazonaws.services.ec2.model.ReplaceNetworkAclEntryRequest; @@ -330,6 +361,8 @@ import com.amazonaws.services.ec2.model.RevokeSecurityGroupEgressRequest; import com.amazonaws.services.ec2.model.RevokeSecurityGroupIngressRequest; import com.amazonaws.services.ec2.model.RunInstancesRequest; import com.amazonaws.services.ec2.model.RunInstancesResult; +import com.amazonaws.services.ec2.model.RunScheduledInstancesRequest; +import com.amazonaws.services.ec2.model.RunScheduledInstancesResult; import com.amazonaws.services.ec2.model.StartInstancesRequest; import com.amazonaws.services.ec2.model.StartInstancesResult; import com.amazonaws.services.ec2.model.StopInstancesRequest; @@ -519,6 +552,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public DeleteNatGatewayResult deleteNatGateway(DeleteNatGatewayRequest deleteNatGatewayRequest) { + return null; + } + @Override public UnmonitorInstancesResult unmonitorInstances(UnmonitorInstancesRequest unmonitorInstancesRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -639,6 +677,16 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public ModifyHostsResult modifyHosts(ModifyHostsRequest modifyHostsRequest) { + return null; + } + + @Override + public void modifyIdFormat(ModifyIdFormatRequest modifyIdFormatRequest) { + + } + @Override public DescribeSecurityGroupsResult describeSecurityGroups(DescribeSecurityGroupsRequest describeSecurityGroupsRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -964,6 +1012,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public DisableVpcClassicLinkDnsSupportResult disableVpcClassicLinkDnsSupport(DisableVpcClassicLinkDnsSupportRequest disableVpcClassicLinkDnsSupportRequest) { + return null; + } + @Override public DescribeInstanceAttributeResult describeInstanceAttribute(DescribeInstanceAttributeRequest describeInstanceAttributeRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -989,6 +1042,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public RunScheduledInstancesResult runScheduledInstances(RunScheduledInstancesRequest runScheduledInstancesRequest) { + return null; + } + @Override public DescribeSubnetsResult describeSubnets(DescribeSubnetsRequest describeSubnetsRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1024,6 +1082,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public ModifyInstancePlacementResult modifyInstancePlacement(ModifyInstancePlacementRequest modifyInstancePlacementRequest) { + return null; + } + @Override public CancelReservedInstancesListingResult cancelReservedInstancesListing(CancelReservedInstancesListingRequest cancelReservedInstancesListingRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1159,6 +1222,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public PurchaseScheduledInstancesResult purchaseScheduledInstances(PurchaseScheduledInstancesRequest purchaseScheduledInstancesRequest) { + return null; + } + @Override public void modifySnapshotAttribute(ModifySnapshotAttributeRequest modifySnapshotAttributeRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1334,6 +1402,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public ReleaseHostsResult releaseHosts(ReleaseHostsRequest releaseHostsRequest) { + return null; + } + @Override public void resetInstanceAttribute(ResetInstanceAttributeRequest resetInstanceAttributeRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1344,6 +1417,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public CreateNatGatewayResult createNatGateway(CreateNatGatewayRequest createNatGatewayRequest) { + return null; + } + @Override public void replaceNetworkAclEntry(ReplaceNetworkAclEntryRequest replaceNetworkAclEntryRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1374,6 +1452,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public EnableVpcClassicLinkDnsSupportResult enableVpcClassicLinkDnsSupport(EnableVpcClassicLinkDnsSupportRequest enableVpcClassicLinkDnsSupportRequest) { + return null; + } + @Override public void createVpnConnectionRoute(CreateVpnConnectionRouteRequest createVpnConnectionRouteRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1489,6 +1572,16 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public DescribeScheduledInstanceAvailabilityResult describeScheduledInstanceAvailability(DescribeScheduledInstanceAvailabilityRequest describeScheduledInstanceAvailabilityRequest) { + return null; + } + + @Override + public DescribeScheduledInstancesResult describeScheduledInstances(DescribeScheduledInstancesRequest describeScheduledInstancesRequest) { + return null; + } + @Override public DescribeDhcpOptionsResult describeDhcpOptions() throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1529,6 +1622,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public DescribeNatGatewaysResult describeNatGateways(DescribeNatGatewaysRequest describeNatGatewaysRequest) { + return null; + } + @Override public DescribeConversionTasksResult describeConversionTasks() throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1544,6 +1642,26 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public DescribeHostsResult describeHosts(DescribeHostsRequest describeHostsRequest) { + return null; + } + + @Override + public DescribeHostsResult describeHosts() { + return null; + } + + @Override + public DescribeIdFormatResult describeIdFormat(DescribeIdFormatRequest describeIdFormatRequest) { + return null; + } + + @Override + public DescribeIdFormatResult describeIdFormat() { + return null; + } + @Override public DescribeVpcPeeringConnectionsResult describeVpcPeeringConnections() throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1584,6 +1702,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public DescribeVpcClassicLinkDnsSupportResult describeVpcClassicLinkDnsSupport(DescribeVpcClassicLinkDnsSupportRequest describeVpcClassicLinkDnsSupportRequest) { + return null; + } + @Override public DescribeClassicLinkInstancesResult describeClassicLinkInstances() throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); @@ -1649,6 +1772,11 @@ public class AmazonEC2Mock implements AmazonEC2 { throw new UnsupportedOperationException("Not supported in mock"); } + @Override + public AllocateHostsResult allocateHosts(AllocateHostsRequest allocateHostsRequest) { + return null; + } + @Override public DescribeSnapshotsResult describeSnapshots() throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); diff --git a/plugins/repository-s3/build.gradle b/plugins/repository-s3/build.gradle index a083309891e..d01ebd29c12 100644 --- a/plugins/repository-s3/build.gradle +++ b/plugins/repository-s3/build.gradle @@ -23,7 +23,7 @@ esplugin { } versions << [ - 'aws': '1.10.33' + 'aws': '1.10.69' ] dependencies { @@ -49,11 +49,6 @@ test { } thirdPartyAudit.excludes = [ - // uses internal java api: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl - // uses internal java api: com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefault - // uses internal java api: com.sun.org.apache.xpath.internal.XPathContext - 'com.amazonaws.util.XpathUtils', - // classes are missing 'javax.servlet.ServletContextEvent', 'javax.servlet.ServletContextListener', @@ -61,3 +56,6 @@ thirdPartyAudit.excludes = [ 'org.apache.log.Hierarchy', 'org.apache.log.Logger', ] + +// AWS SDK is exposing some deprecated methods which we call using a delegate +compileTestJava.options.compilerArgs << "-Xlint:-deprecation" diff --git a/plugins/repository-s3/licenses/aws-java-sdk-core-1.10.33.jar.sha1 b/plugins/repository-s3/licenses/aws-java-sdk-core-1.10.33.jar.sha1 deleted file mode 100644 index 332a8f01035..00000000000 --- a/plugins/repository-s3/licenses/aws-java-sdk-core-1.10.33.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -fabedbbe2b834b1add150b6a38395c5ef7380168 \ No newline at end of file diff --git a/plugins/repository-s3/licenses/aws-java-sdk-core-1.10.69.jar.sha1 b/plugins/repository-s3/licenses/aws-java-sdk-core-1.10.69.jar.sha1 new file mode 100644 index 00000000000..2971a33d7d9 --- /dev/null +++ b/plugins/repository-s3/licenses/aws-java-sdk-core-1.10.69.jar.sha1 @@ -0,0 +1 @@ +a1f02d5f26ba1d8c37e2bf9c847db3c6729dda00 \ No newline at end of file diff --git a/plugins/repository-s3/licenses/aws-java-sdk-kms-1.10.33.jar.sha1 b/plugins/repository-s3/licenses/aws-java-sdk-kms-1.10.33.jar.sha1 deleted file mode 100644 index 0d7ab9f8381..00000000000 --- a/plugins/repository-s3/licenses/aws-java-sdk-kms-1.10.33.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -35881245894ecc4d893c074eacdf2e6b56820fda \ No newline at end of file diff --git a/plugins/repository-s3/licenses/aws-java-sdk-kms-1.10.69.jar.sha1 b/plugins/repository-s3/licenses/aws-java-sdk-kms-1.10.69.jar.sha1 new file mode 100644 index 00000000000..22e1f924664 --- /dev/null +++ b/plugins/repository-s3/licenses/aws-java-sdk-kms-1.10.69.jar.sha1 @@ -0,0 +1 @@ +ed74ff3872193b4704a751f0b72ab2cf0db0651b \ No newline at end of file diff --git a/plugins/repository-s3/licenses/aws-java-sdk-s3-1.10.33.jar.sha1 b/plugins/repository-s3/licenses/aws-java-sdk-s3-1.10.33.jar.sha1 deleted file mode 100644 index 3328f01c658..00000000000 --- a/plugins/repository-s3/licenses/aws-java-sdk-s3-1.10.33.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -5665cf77102a932a16e99ebf41d197e03ddbf25c \ No newline at end of file diff --git a/plugins/repository-s3/licenses/aws-java-sdk-s3-1.10.69.jar.sha1 b/plugins/repository-s3/licenses/aws-java-sdk-s3-1.10.69.jar.sha1 new file mode 100644 index 00000000000..64e7336c2bc --- /dev/null +++ b/plugins/repository-s3/licenses/aws-java-sdk-s3-1.10.69.jar.sha1 @@ -0,0 +1 @@ +6fa48bf0bff43f26436956b88d8d3764b6cf109e \ No newline at end of file diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/AmazonS3Wrapper.java b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/AmazonS3Wrapper.java index 97829f9d689..7cda9ee0947 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/AmazonS3Wrapper.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/AmazonS3Wrapper.java @@ -50,6 +50,7 @@ import com.amazonaws.services.s3.model.CreateBucketRequest; import com.amazonaws.services.s3.model.DeleteBucketCrossOriginConfigurationRequest; import com.amazonaws.services.s3.model.DeleteBucketLifecycleConfigurationRequest; import com.amazonaws.services.s3.model.DeleteBucketPolicyRequest; +import com.amazonaws.services.s3.model.DeleteBucketReplicationConfigurationRequest; import com.amazonaws.services.s3.model.DeleteBucketRequest; import com.amazonaws.services.s3.model.DeleteBucketTaggingConfigurationRequest; import com.amazonaws.services.s3.model.DeleteBucketWebsiteConfigurationRequest; @@ -69,6 +70,7 @@ import com.amazonaws.services.s3.model.GetBucketReplicationConfigurationRequest; import com.amazonaws.services.s3.model.GetBucketTaggingConfigurationRequest; import com.amazonaws.services.s3.model.GetBucketVersioningConfigurationRequest; import com.amazonaws.services.s3.model.GetBucketWebsiteConfigurationRequest; +import com.amazonaws.services.s3.model.GetObjectAclRequest; import com.amazonaws.services.s3.model.GetObjectMetadataRequest; import com.amazonaws.services.s3.model.GetObjectRequest; import com.amazonaws.services.s3.model.GetS3AccountOwnerRequest; @@ -253,6 +255,11 @@ public class AmazonS3Wrapper implements AmazonS3 { return delegate.getObjectAcl(bucketName, key, versionId); } + @Override + public AccessControlList getObjectAcl(GetObjectAclRequest getObjectAclRequest) throws AmazonClientException, AmazonServiceException { + return delegate.getObjectAcl(getObjectAclRequest); + } + @Override public void setObjectAcl(String bucketName, String key, AccessControlList acl) throws AmazonClientException, AmazonServiceException { delegate.setObjectAcl(bucketName, key, acl); @@ -358,6 +365,17 @@ public class AmazonS3Wrapper implements AmazonS3 { delegate.deleteBucketReplicationConfiguration(bucketName); } + @Override + public void deleteBucketReplicationConfiguration(DeleteBucketReplicationConfigurationRequest request) throws AmazonServiceException, + AmazonClientException { + delegate.deleteBucketReplicationConfiguration(request); + } + + @Override + public boolean doesObjectExist(String bucketName, String objectName) throws AmazonServiceException, AmazonClientException { + return delegate.doesObjectExist(bucketName, objectName); + } + @Override public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException { return delegate.putObject(putObjectRequest); From 44080a007f08a90d7eb266429a3826b074ab88bf Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 15 Apr 2016 14:52:27 +0200 Subject: [PATCH 02/87] Add cloud.aws.s3.throttle_retries setting Defaults to `true`. If anyone is having trouble with this option, you could disable it with `cloud.aws.s3.throttle_retries: false` in `elasticsearch.yml` file. --- .../main/java/org/elasticsearch/cloud/aws/AwsS3Service.java | 4 ++++ .../org/elasticsearch/cloud/aws/InternalAwsS3Service.java | 1 + .../plugin/repository/s3/S3RepositoryPlugin.java | 1 + 3 files changed, 6 insertions(+) diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java index 427c454fa28..383be6825c2 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java @@ -151,6 +151,10 @@ public interface AwsS3Service extends LifecycleComponent { * cloud.aws.s3.endpoint: Endpoint. If not set, endpoint will be guessed based on region setting. */ Setting ENDPOINT_SETTING = Setting.simpleString("cloud.aws.s3.endpoint", Property.NodeScope); + /** + * cloud.aws.s3.throttle_retries: Set to `true` if you want to throttle retries. Defaults to `true`. + */ + Setting THROTTLE_RETRIES_SETTING = Setting.boolSetting("cloud.aws.s3.throttle_retries", true, Property.NodeScope); } AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries); diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java index 81b6463a746..67fae30657d 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java @@ -101,6 +101,7 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent Date: Fri, 29 Apr 2016 14:40:02 +0200 Subject: [PATCH 03/87] Add new UnsupportedException for EC Mock --- .../discovery/ec2/AmazonEC2Mock.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AmazonEC2Mock.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AmazonEC2Mock.java index 881cb98e1d1..49f4f885419 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AmazonEC2Mock.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AmazonEC2Mock.java @@ -554,7 +554,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public DeleteNatGatewayResult deleteNatGateway(DeleteNatGatewayRequest deleteNatGatewayRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -679,12 +679,12 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public ModifyHostsResult modifyHosts(ModifyHostsRequest modifyHostsRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override public void modifyIdFormat(ModifyIdFormatRequest modifyIdFormatRequest) { - + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1014,7 +1014,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public DisableVpcClassicLinkDnsSupportResult disableVpcClassicLinkDnsSupport(DisableVpcClassicLinkDnsSupportRequest disableVpcClassicLinkDnsSupportRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1044,7 +1044,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public RunScheduledInstancesResult runScheduledInstances(RunScheduledInstancesRequest runScheduledInstancesRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1084,7 +1084,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public ModifyInstancePlacementResult modifyInstancePlacement(ModifyInstancePlacementRequest modifyInstancePlacementRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1224,7 +1224,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public PurchaseScheduledInstancesResult purchaseScheduledInstances(PurchaseScheduledInstancesRequest purchaseScheduledInstancesRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1404,7 +1404,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public ReleaseHostsResult releaseHosts(ReleaseHostsRequest releaseHostsRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1419,7 +1419,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public CreateNatGatewayResult createNatGateway(CreateNatGatewayRequest createNatGatewayRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1454,7 +1454,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public EnableVpcClassicLinkDnsSupportResult enableVpcClassicLinkDnsSupport(EnableVpcClassicLinkDnsSupportRequest enableVpcClassicLinkDnsSupportRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1574,12 +1574,12 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public DescribeScheduledInstanceAvailabilityResult describeScheduledInstanceAvailability(DescribeScheduledInstanceAvailabilityRequest describeScheduledInstanceAvailabilityRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override public DescribeScheduledInstancesResult describeScheduledInstances(DescribeScheduledInstancesRequest describeScheduledInstancesRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1624,7 +1624,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public DescribeNatGatewaysResult describeNatGateways(DescribeNatGatewaysRequest describeNatGatewaysRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1644,22 +1644,22 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public DescribeHostsResult describeHosts(DescribeHostsRequest describeHostsRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override public DescribeHostsResult describeHosts() { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override public DescribeIdFormatResult describeIdFormat(DescribeIdFormatRequest describeIdFormatRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override public DescribeIdFormatResult describeIdFormat() { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1704,7 +1704,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public DescribeVpcClassicLinkDnsSupportResult describeVpcClassicLinkDnsSupport(DescribeVpcClassicLinkDnsSupportRequest describeVpcClassicLinkDnsSupportRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override @@ -1774,7 +1774,7 @@ public class AmazonEC2Mock implements AmazonEC2 { @Override public AllocateHostsResult allocateHosts(AllocateHostsRequest allocateHostsRequest) { - return null; + throw new UnsupportedOperationException("Not supported in mock"); } @Override From e289de6e96520aaba42f98fb284ccd4dac7fc7d5 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Thu, 19 May 2016 16:50:37 +0200 Subject: [PATCH 04/87] Move `throttle_retries` under `repositories.s3.` prefix or per repository I initially wrongly put this setting under `cloud.aws.s3.` prefix which does not make sense. It should be placed at the same place as `max_retries`. Also applied @tlrx comments. We should set this even if max_retries is not set (when using default values). Also added some documentation about this setting. --- docs/plugins/repository-s3.asciidoc | 13 ++++++++++-- .../elasticsearch/cloud/aws/AwsS3Service.java | 7 ++----- .../cloud/aws/InternalAwsS3Service.java | 10 +++++---- .../repository/s3/S3RepositoryPlugin.java | 3 ++- .../repositories/s3/S3Repository.java | 21 ++++++++++++++++--- .../cloud/aws/TestAwsS3Service.java | 5 +++-- .../s3/AbstractS3SnapshotRestoreTest.java | 5 +++-- 7 files changed, 45 insertions(+), 19 deletions(-) diff --git a/docs/plugins/repository-s3.asciidoc b/docs/plugins/repository-s3.asciidoc index 8780b3a710e..f862fcb7cdb 100644 --- a/docs/plugins/repository-s3.asciidoc +++ b/docs/plugins/repository-s3.asciidoc @@ -39,7 +39,8 @@ http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html credentials for authentication. These can be overridden by, in increasing order of precedence, system properties `aws.accessKeyId` and `aws.secretKey`, environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY`, or the -elasticsearch config using `cloud.aws.access_key` and `cloud.aws.secret_key`: +elasticsearch config using `cloud.aws.access_key` and `cloud.aws.secret_key` or +if you wish to set credentials specifically for s3 `cloud.aws.s3.access_key` and `cloud.aws.s3.secret_key`: [source,yaml] ---- @@ -106,6 +107,7 @@ cloud: ===== Region The `cloud.aws.region` can be set to a region and will automatically use the relevant settings for both `ec2` and `s3`. +You can specifically set it for s3 only using `cloud.aws.s3.region`. The available values are: * `us-east` (`us-east-1`) @@ -216,9 +218,13 @@ The following settings are supported: Number of retries in case of S3 errors. Defaults to `3`. +`throttle_retries`:: + + Set to `true` if you want to throttle retries. Defaults to AWS SDK default value (`false`). + `read_only`:: - Makes repository read-only. coming[2.1.0] Defaults to `false`. + Makes repository read-only. Defaults to `false`. `canned_acl`:: @@ -236,6 +242,9 @@ The following settings are supported: currently supported by the plugin. For more information about the different classes, see http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS Storage Classes Guide] +Note that you can define S3 repository settings for all S3 repositories in `elasticsearch.yml` configuration file. +They are all prefixed with `repositories.s3.`. + The S3 repositories use the same credentials as the rest of the AWS services provided by this plugin (`discovery`). See <> for details. diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java index 383be6825c2..59a1dbff45f 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java @@ -151,11 +151,8 @@ public interface AwsS3Service extends LifecycleComponent { * cloud.aws.s3.endpoint: Endpoint. If not set, endpoint will be guessed based on region setting. */ Setting ENDPOINT_SETTING = Setting.simpleString("cloud.aws.s3.endpoint", Property.NodeScope); - /** - * cloud.aws.s3.throttle_retries: Set to `true` if you want to throttle retries. Defaults to `true`. - */ - Setting THROTTLE_RETRIES_SETTING = Setting.boolSetting("cloud.aws.s3.throttle_retries", true, Property.NodeScope); } - AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries); + AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries, + boolean throttleRetries); } diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java index 67fae30657d..887e8ba61d9 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java @@ -57,7 +57,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent clientDescriptor = new Tuple<>(endpoint, account); AmazonS3Client client = clients.get(clientDescriptor); if (client != null) { @@ -101,8 +103,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent MAX_RETRIES_SETTING = Setting.intSetting("repositories.s3.max_retries", 3, Property.NodeScope); + /** + * repositories.s3.throttle_retries: Set to `true` if you want to throttle retries. Defaults to AWS SDK default value (`false`). + */ + Setting THROTTLE_RETRIES_SETTING = Setting.boolSetting("repositories.s3.throttle_retries", + ClientConfiguration.DEFAULT_THROTTLE_RETRIES, Property.NodeScope); /** * repositories.s3.chunk_size: Big files can be broken down into chunks during snapshotting if needed. Defaults to 1g. */ @@ -196,6 +202,12 @@ public class S3Repository extends BlobStoreRepository { * @see Repositories#MAX_RETRIES_SETTING */ Setting MAX_RETRIES_SETTING = Setting.intSetting("max_retries", 3, Property.NodeScope); + /** + * throttle_retries + * @see Repositories#THROTTLE_RETRIES_SETTING + */ + Setting THROTTLE_RETRIES_SETTING = Setting.boolSetting("throttle_retries", + ClientConfiguration.DEFAULT_THROTTLE_RETRIES, Property.NodeScope); /** * chunk_size * @see Repositories#CHUNK_SIZE_SETTING @@ -262,6 +274,7 @@ public class S3Repository extends BlobStoreRepository { boolean serverSideEncryption = getValue(repositorySettings, Repository.SERVER_SIDE_ENCRYPTION_SETTING, Repositories.SERVER_SIDE_ENCRYPTION_SETTING); ByteSizeValue bufferSize = getValue(repositorySettings, Repository.BUFFER_SIZE_SETTING, Repositories.BUFFER_SIZE_SETTING); Integer maxRetries = getValue(repositorySettings, Repository.MAX_RETRIES_SETTING, Repositories.MAX_RETRIES_SETTING); + boolean throttleRetries = getValue(repositorySettings, Repository.THROTTLE_RETRIES_SETTING, Repositories.THROTTLE_RETRIES_SETTING); this.chunkSize = getValue(repositorySettings, Repository.CHUNK_SIZE_SETTING, Repositories.CHUNK_SIZE_SETTING); this.compress = getValue(repositorySettings, Repository.COMPRESS_SETTING, Repositories.COMPRESS_SETTING); @@ -275,13 +288,15 @@ public class S3Repository extends BlobStoreRepository { String storageClass = getValue(repositorySettings, Repository.STORAGE_CLASS_SETTING, Repositories.STORAGE_CLASS_SETTING); String cannedACL = getValue(repositorySettings, Repository.CANNED_ACL_SETTING, Repositories.CANNED_ACL_SETTING); - logger.debug("using bucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], buffer_size [{}], max_retries [{}], cannedACL [{}], storageClass [{}]", - bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries, cannedACL, storageClass); + logger.debug("using bucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], " + + "buffer_size [{}], max_retries [{}], throttle_retries [{}], cannedACL [{}], storageClass [{}]", + bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries, throttleRetries, cannedACL, + storageClass); String key = getValue(repositorySettings, Repository.KEY_SETTING, Repositories.KEY_SETTING); String secret = getValue(repositorySettings, Repository.SECRET_SETTING, Repositories.SECRET_SETTING); - blobStore = new S3BlobStore(settings, s3Service.client(endpoint, protocol, region, key, secret, maxRetries), + blobStore = new S3BlobStore(settings, s3Service.client(endpoint, protocol, region, key, secret, maxRetries, throttleRetries), bucket, region, serverSideEncryption, bufferSize, maxRetries, cannedACL, storageClass); String basePath = getValue(repositorySettings, Repository.BASE_PATH_SETTING, Repositories.BASE_PATH_SETTING); diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java index 47e884d73bd..1a3ce418c0b 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java @@ -51,8 +51,9 @@ public class TestAwsS3Service extends InternalAwsS3Service { @Override - public synchronized AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries) { - return cachedWrapper(super.client(endpoint, protocol, region, account, key, maxRetries)); + public synchronized AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries, + boolean throttleRetries) { + return cachedWrapper(super.client(endpoint, protocol, region, account, key, maxRetries, throttleRetries)); } private AmazonS3 cachedWrapper(AmazonS3 client) { diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java b/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java index 743e2645ab2..2e196610c1a 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java @@ -200,7 +200,7 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase S3Repository.Repositories.REGION_SETTING.get(settings), S3Repository.Repositories.KEY_SETTING.get(settings), S3Repository.Repositories.SECRET_SETTING.get(settings), - null); + null, randomBoolean()); String bucketName = bucket.get("bucket"); logger.info("--> verify encryption for bucket [{}], prefix [{}]", bucketName, basePath); @@ -475,7 +475,8 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase // We check that settings has been set in elasticsearch.yml integration test file // as described in README assertThat("Your settings in elasticsearch.yml are incorrects. Check README file.", bucketName, notNullValue()); - AmazonS3 client = internalCluster().getInstance(AwsS3Service.class).client(endpoint, protocol, region, accessKey, secretKey, null); + AmazonS3 client = internalCluster().getInstance(AwsS3Service.class).client(endpoint, protocol, region, accessKey, secretKey, + null, randomBoolean()); try { ObjectListing prevListing = null; //From http://docs.amazonwebservices.com/AmazonS3/latest/dev/DeletingMultipleObjectsUsingJava.html From a445654123b783469b0a8afd90f669dfcd8e9204 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 27 May 2016 10:13:16 +0200 Subject: [PATCH 05/87] Fix after review * changes `throttle_retries` to `use_throttle_retries` * removes registering of all individual repository settings when the plugin starts. Not needed * adds more comment about deprecated method in AWS SDK we need to implement though in a Delegate class within our tests --- docs/plugins/repository-s3.asciidoc | 5 +++-- plugins/repository-s3/build.gradle | 4 +++- .../elasticsearch/cloud/aws/AwsS3Service.java | 2 +- .../cloud/aws/InternalAwsS3Service.java | 8 ++++---- .../repository/s3/S3RepositoryPlugin.java | 19 +------------------ .../repositories/s3/S3Repository.java | 16 ++++++++-------- .../cloud/aws/TestAwsS3Service.java | 4 ++-- 7 files changed, 22 insertions(+), 36 deletions(-) diff --git a/docs/plugins/repository-s3.asciidoc b/docs/plugins/repository-s3.asciidoc index b4b34ee6059..fc07e6ae65a 100644 --- a/docs/plugins/repository-s3.asciidoc +++ b/docs/plugins/repository-s3.asciidoc @@ -218,7 +218,7 @@ The following settings are supported: Number of retries in case of S3 errors. Defaults to `3`. -`throttle_retries`:: +`use_throttle_retries`:: Set to `true` if you want to throttle retries. Defaults to AWS SDK default value (`false`). @@ -243,7 +243,8 @@ The following settings are supported: different classes, see http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS Storage Classes Guide] Note that you can define S3 repository settings for all S3 repositories in `elasticsearch.yml` configuration file. -They are all prefixed with `repositories.s3.`. +They are all prefixed with `repositories.s3.`. For example, you can define compression for all S3 repositories +by setting `repositories.s3.compress: true` in `elasticsearch.yml`. The S3 repositories use the same credentials as the rest of the AWS services provided by this plugin (`discovery`). See <> for details. diff --git a/plugins/repository-s3/build.gradle b/plugins/repository-s3/build.gradle index d01ebd29c12..8ff92a0a20b 100644 --- a/plugins/repository-s3/build.gradle +++ b/plugins/repository-s3/build.gradle @@ -57,5 +57,7 @@ thirdPartyAudit.excludes = [ 'org.apache.log.Logger', ] -// AWS SDK is exposing some deprecated methods which we call using a delegate +// AWS SDK is exposing some deprecated methods which we call using a delegate: +// * setObjectRedirectLocation(String bucketName, String key, String newRedirectLocation) +// * changeObjectStorageClass(String bucketName, String key, StorageClass newStorageClass) compileTestJava.options.compilerArgs << "-Xlint:-deprecation" diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java index 59a1dbff45f..17e5de37b7c 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java @@ -154,5 +154,5 @@ public interface AwsS3Service extends LifecycleComponent { } AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries, - boolean throttleRetries); + boolean useThrottleRetries); } diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java index 887e8ba61d9..352aa196b06 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java @@ -58,7 +58,7 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent clientDescriptor = new Tuple<>(endpoint, account); AmazonS3Client client = clients.get(clientDescriptor); if (client != null) { @@ -104,7 +104,7 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent MAX_RETRIES_SETTING = Setting.intSetting("repositories.s3.max_retries", 3, Property.NodeScope); /** - * repositories.s3.throttle_retries: Set to `true` if you want to throttle retries. Defaults to AWS SDK default value (`false`). + * repositories.s3.use_throttle_retries: Set to `true` if you want to throttle retries. Defaults to AWS SDK default value (`false`). */ - Setting THROTTLE_RETRIES_SETTING = Setting.boolSetting("repositories.s3.throttle_retries", + Setting USE_THROTTLE_RETRIES_SETTING = Setting.boolSetting("repositories.s3.use_throttle_retries", ClientConfiguration.DEFAULT_THROTTLE_RETRIES, Property.NodeScope); /** * repositories.s3.chunk_size: Big files can be broken down into chunks during snapshotting if needed. Defaults to 1g. @@ -203,10 +203,10 @@ public class S3Repository extends BlobStoreRepository { */ Setting MAX_RETRIES_SETTING = Setting.intSetting("max_retries", 3, Property.NodeScope); /** - * throttle_retries - * @see Repositories#THROTTLE_RETRIES_SETTING + * use_throttle_retries + * @see Repositories#USE_THROTTLE_RETRIES_SETTING */ - Setting THROTTLE_RETRIES_SETTING = Setting.boolSetting("throttle_retries", + Setting USE_THROTTLE_RETRIES_SETTING = Setting.boolSetting("use_throttle_retries", ClientConfiguration.DEFAULT_THROTTLE_RETRIES, Property.NodeScope); /** * chunk_size @@ -274,7 +274,7 @@ public class S3Repository extends BlobStoreRepository { boolean serverSideEncryption = getValue(repositorySettings, Repository.SERVER_SIDE_ENCRYPTION_SETTING, Repositories.SERVER_SIDE_ENCRYPTION_SETTING); ByteSizeValue bufferSize = getValue(repositorySettings, Repository.BUFFER_SIZE_SETTING, Repositories.BUFFER_SIZE_SETTING); Integer maxRetries = getValue(repositorySettings, Repository.MAX_RETRIES_SETTING, Repositories.MAX_RETRIES_SETTING); - boolean throttleRetries = getValue(repositorySettings, Repository.THROTTLE_RETRIES_SETTING, Repositories.THROTTLE_RETRIES_SETTING); + boolean useThrottleRetries = getValue(repositorySettings, Repository.USE_THROTTLE_RETRIES_SETTING, Repositories.USE_THROTTLE_RETRIES_SETTING); this.chunkSize = getValue(repositorySettings, Repository.CHUNK_SIZE_SETTING, Repositories.CHUNK_SIZE_SETTING); this.compress = getValue(repositorySettings, Repository.COMPRESS_SETTING, Repositories.COMPRESS_SETTING); @@ -290,13 +290,13 @@ public class S3Repository extends BlobStoreRepository { logger.debug("using bucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], " + "buffer_size [{}], max_retries [{}], throttle_retries [{}], cannedACL [{}], storageClass [{}]", - bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries, throttleRetries, cannedACL, + bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries, useThrottleRetries, cannedACL, storageClass); String key = getValue(repositorySettings, Repository.KEY_SETTING, Repositories.KEY_SETTING); String secret = getValue(repositorySettings, Repository.SECRET_SETTING, Repositories.SECRET_SETTING); - blobStore = new S3BlobStore(settings, s3Service.client(endpoint, protocol, region, key, secret, maxRetries, throttleRetries), + blobStore = new S3BlobStore(settings, s3Service.client(endpoint, protocol, region, key, secret, maxRetries, useThrottleRetries), bucket, region, serverSideEncryption, bufferSize, maxRetries, cannedACL, storageClass); String basePath = getValue(repositorySettings, Repository.BASE_PATH_SETTING, Repositories.BASE_PATH_SETTING); diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java index 1a3ce418c0b..d8ddd3e7162 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java @@ -52,8 +52,8 @@ public class TestAwsS3Service extends InternalAwsS3Service { @Override public synchronized AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries, - boolean throttleRetries) { - return cachedWrapper(super.client(endpoint, protocol, region, account, key, maxRetries, throttleRetries)); + boolean useThrottleRetries) { + return cachedWrapper(super.client(endpoint, protocol, region, account, key, maxRetries, useThrottleRetries)); } private AmazonS3 cachedWrapper(AmazonS3 client) { From 63622aa6b650ef7af684fe905208913985a92192 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 27 May 2016 12:48:05 +0200 Subject: [PATCH 06/87] Fix log use_throttle_retries --- .../java/org/elasticsearch/repositories/s3/S3Repository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java b/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java index 9954c2006bb..fe184a06aef 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java @@ -289,7 +289,7 @@ public class S3Repository extends BlobStoreRepository { String cannedACL = getValue(repositorySettings, Repository.CANNED_ACL_SETTING, Repositories.CANNED_ACL_SETTING); logger.debug("using bucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], " + - "buffer_size [{}], max_retries [{}], throttle_retries [{}], cannedACL [{}], storageClass [{}]", + "buffer_size [{}], max_retries [{}], use_throttle_retries [{}], cannedACL [{}], storageClass [{}]", bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries, useThrottleRetries, cannedACL, storageClass); From a30437f2505a1599bffd14be7a36c67489687dad Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Fri, 3 Jun 2016 14:52:54 -0400 Subject: [PATCH 07/87] adds _rollover api --- .../elasticsearch/action/ActionModule.java | 3 + ...dicesAliasesClusterStateUpdateRequest.java | 2 +- .../admin/indices/rollover/Condition.java | 105 +++++++ .../indices/rollover/RolloverAction.java | 45 +++ .../indices/rollover/RolloverRequest.java | 164 +++++++++++ .../rollover/RolloverRequestBuilder.java | 58 ++++ .../indices/rollover/RolloverResponse.java | 62 +++++ .../rollover/TransportRolloverAction.java | 257 ++++++++++++++++++ .../client/IndicesAdminClient.java | 18 ++ .../client/support/AbstractClient.java | 19 ++ .../common/network/NetworkModule.java | 2 + .../indices/RestRolloverIndexAction.java | 72 +++++ .../admin/indices/rollover/RolloverIT.java | 105 +++++++ .../TransportRolloverActionTests.java | 192 +++++++++++++ .../rest-api-spec/api/indices.rollover.json | 35 +++ .../test/indices.rollover/10_basic.yaml | 69 +++++ 16 files changed, 1207 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java create mode 100644 core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverAction.java create mode 100644 core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java create mode 100644 core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java create mode 100644 core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java create mode 100644 core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java create mode 100644 core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java create mode 100644 core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml diff --git a/core/src/main/java/org/elasticsearch/action/ActionModule.java b/core/src/main/java/org/elasticsearch/action/ActionModule.java index 7e975b922d4..316b2b9aaa0 100644 --- a/core/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/core/src/main/java/org/elasticsearch/action/ActionModule.java @@ -107,6 +107,8 @@ import org.elasticsearch.action.admin.indices.recovery.RecoveryAction; import org.elasticsearch.action.admin.indices.recovery.TransportRecoveryAction; import org.elasticsearch.action.admin.indices.refresh.RefreshAction; import org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction; +import org.elasticsearch.action.admin.indices.rollover.RolloverAction; +import org.elasticsearch.action.admin.indices.rollover.TransportRolloverAction; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction; import org.elasticsearch.action.admin.indices.segments.TransportIndicesSegmentsAction; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction; @@ -289,6 +291,7 @@ public class ActionModule extends AbstractModule { registerAction(IndicesShardStoresAction.INSTANCE, TransportIndicesShardStoresAction.class); registerAction(CreateIndexAction.INSTANCE, TransportCreateIndexAction.class); registerAction(ShrinkAction.INSTANCE, TransportShrinkAction.class); + registerAction(RolloverAction.INSTANCE, TransportRolloverAction.class); registerAction(DeleteIndexAction.INSTANCE, TransportDeleteIndexAction.class); registerAction(GetIndexAction.INSTANCE, TransportGetIndexAction.class); registerAction(OpenIndexAction.INSTANCE, TransportOpenIndexAction.class); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesClusterStateUpdateRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesClusterStateUpdateRequest.java index 30cbd6d9ec7..42d34d6ebd7 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesClusterStateUpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesClusterStateUpdateRequest.java @@ -28,7 +28,7 @@ public class IndicesAliasesClusterStateUpdateRequest extends ClusterStateUpdateR AliasAction[] actions; - IndicesAliasesClusterStateUpdateRequest() { + public IndicesAliasesClusterStateUpdateRequest() { } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java new file mode 100644 index 00000000000..c5ef9b4c51b --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java @@ -0,0 +1,105 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.common.unit.TimeValue; + +import java.util.Locale; + +public class Condition { + + public enum ConditionType { + MAX_SIZE((byte) 0), + MAX_AGE((byte) 1), + MAX_DOCS((byte) 2); + + private final byte id; + + ConditionType(byte id) { + this.id = id; + } + + public byte getId() { + return id; + } + + public static ConditionType fromId(byte id) { + if (id == 0) { + return MAX_SIZE; + } else if (id == 1) { + return MAX_AGE; + } else if (id == 2) { + return MAX_DOCS; + } else { + throw new IllegalArgumentException("no condition type [" + id + "]"); + } + } + + public static ConditionType fromString(String type) { + final String typeString = type.toLowerCase(Locale.ROOT); + switch (typeString) { + case "max_size": + return MAX_SIZE; + case "max_age": + return MAX_AGE; + case "max_docs": + return MAX_DOCS; + default: + throw new IllegalArgumentException("no condition type [" + type + "]"); + } + } + + public static long parseFromString(ConditionType condition, String value) { + switch (condition) { + case MAX_SIZE: + return ByteSizeValue.parseBytesSizeValue(value, MAX_SIZE.name().toLowerCase(Locale.ROOT)).getBytes(); + case MAX_AGE: + return TimeValue.parseTimeValue(value, MAX_AGE.name().toLowerCase(Locale.ROOT)).getMillis(); + case MAX_DOCS: + try { + return Long.valueOf(value); + } catch (NumberFormatException e) { + throw new ElasticsearchParseException("Failed to parse setting [{}] with value [{}] as long", e, + MAX_DOCS.name().toLowerCase(Locale.ROOT), value); + } + default: + throw new ElasticsearchParseException("condition [" + condition + "] not recognized"); + } + } + } + + private final ConditionType type; + private final long value; + + public Condition(ConditionType type, long value) { + this.type = type; + this.value = value; + } + + public ConditionType getType() { + return type; + } + + public long getValue() { + return value; + } +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverAction.java new file mode 100644 index 00000000000..dd9d50dac73 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverAction.java @@ -0,0 +1,45 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; + +/** + */ +public class RolloverAction extends Action { + + public static final RolloverAction INSTANCE = new RolloverAction(); + public static final String NAME = "indices:admin/rollover"; + + private RolloverAction() { + super(NAME); + } + + @Override + public RolloverResponse newResponse() { + return new RolloverResponse(); + } + + @Override + public RolloverRequestBuilder newRequestBuilder(ElasticsearchClient client) { + return new RolloverRequestBuilder(client, this); + } +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java new file mode 100644 index 00000000000..4a233bf2d81 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -0,0 +1,164 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.IndicesRequest; +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.action.support.master.AcknowledgedRequest; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.elasticsearch.action.ValidateActions.addValidationError; + +/** + * Request class to swap index under an alias given some predicates + * TODO: documentation + */ +public class RolloverRequest extends AcknowledgedRequest implements IndicesRequest { + + private String sourceAlias; + private String optionalTargetAlias; + private List conditions = new ArrayList<>(); + + RolloverRequest() {} + + public RolloverRequest(String sourceAlias, String optionalTargetAlias) { + this.sourceAlias = sourceAlias; + this.optionalTargetAlias = optionalTargetAlias; + } + + @Override + public ActionRequestValidationException validate() { + ActionRequestValidationException validationException = null; + if (sourceAlias == null) { + validationException = addValidationError("source alias is missing", validationException); + } + return validationException; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + sourceAlias = in.readString(); + optionalTargetAlias = in.readOptionalString(); + int size = in.readVInt(); + for (int i = 0; i < size; i++) { + Condition.ConditionType type = Condition.ConditionType.fromId(in.readByte()); + long value = in.readLong(); + this.conditions.add(new Condition(type, value)); + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(sourceAlias); + out.writeOptionalString(optionalTargetAlias); + out.writeVInt(conditions.size()); + for (Condition condition : conditions) { + out.writeByte(condition.getType().getId()); + out.writeLong(condition.getValue()); + } + } + + @Override + public String[] indices() { + return new String[] {sourceAlias}; + } + + @Override + public IndicesOptions indicesOptions() { + return IndicesOptions.strictSingleIndexNoExpandForbidClosed(); + } + + public void setSourceAlias(String sourceAlias) { + this.sourceAlias = sourceAlias; + } + + public void setOptionalTargetAlias(String optionalTargetAlias) { + this.optionalTargetAlias = optionalTargetAlias; + } + + public void addMaxIndexAgeCondition(String age) { + addCondition(Condition.ConditionType.MAX_AGE, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_AGE, age)); + } + + public void addMaxIndexDocsCondition(String docs) { + addCondition(Condition.ConditionType.MAX_DOCS, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_DOCS, docs)); + } + + public void addMaxIndexSizeCondition(String size) { + addCondition(Condition.ConditionType.MAX_SIZE, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_SIZE, size)); + } + + private void addCondition(Condition.ConditionType conditionType, long value) { + this.conditions.add(new Condition(conditionType, value)); + } + + public List getConditions() { + return conditions; + } + + public String getSourceAlias() { + return sourceAlias; + } + + public String getOptionalTargetAlias() { + return optionalTargetAlias; + } + + public void source(BytesReference source) { + XContentType xContentType = XContentFactory.xContentType(source); + if (xContentType != null) { + try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(source)) { + source(parser.map()); + } catch (IOException e) { + throw new ElasticsearchParseException("failed to parse source for rollover index", e); + } + } else { + throw new ElasticsearchParseException("failed to parse content type for rollover index source"); + } + } + + private void source(Map map) { + for (Map.Entry entry : map.entrySet()) { + if (entry.getKey().equals("conditions")) { + final Map conditions = (Map) entry.getValue(); + for (Map.Entry conditionEntry : conditions.entrySet()) { + final Condition.ConditionType conditionType = Condition.ConditionType.fromString(conditionEntry.getKey()); + this.addCondition(conditionType, Condition.ConditionType.parseFromString(conditionType, + conditionEntry.getValue())); + } + } else { + throw new ElasticsearchParseException("unknown property [" + entry.getKey() + "]"); + } + } + } +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java new file mode 100644 index 00000000000..c42bb9cbd83 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -0,0 +1,58 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; +import org.elasticsearch.client.ElasticsearchClient; + + +/** + * TODO: Documentation + */ +public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder { + public RolloverRequestBuilder(ElasticsearchClient client, RolloverAction action) { + super(client, action, new RolloverRequest()); + } + + public RolloverRequestBuilder setSourceAlias(String sourceAlias) { + this.request.setSourceAlias(sourceAlias); + return this; + } + + public RolloverRequestBuilder setOptionalTargetAlias(String optionalTargetAlias) { + this.request.setOptionalTargetAlias(optionalTargetAlias); + return this; + } + + public RolloverRequestBuilder addMaxIndexSizeCondition(String size) { + this.request.addMaxIndexSizeCondition(size); + return this; + } + + public RolloverRequestBuilder addMaxIndexAgeCondition(String age) { + this.request.addMaxIndexAgeCondition(age); + return this; + } + + public RolloverRequestBuilder addMaxIndexDocsCondition(String docs) { + this.request.addMaxIndexDocsCondition(docs); + return this; + } +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java new file mode 100644 index 00000000000..79722e73755 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java @@ -0,0 +1,62 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + +public final class RolloverResponse extends ActionResponse { + + private String oldIndex; + private String newIndex; + + RolloverResponse() { + } + + RolloverResponse(String oldIndex, String newIndex) { + this.oldIndex = oldIndex; + this.newIndex = newIndex; + } + + public String getOldIndex() { + return oldIndex; + } + + public String getNewIndex() { + return newIndex; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + oldIndex = in.readString(); + newIndex = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(oldIndex); + out.writeString(newIndex); + } +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java new file mode 100644 index 00000000000..fcd9e2d96cf --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -0,0 +1,257 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest; +import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.action.support.master.TransportMasterNodeAction; +import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse; +import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.block.ClusterBlockLevel; +import org.elasticsearch.cluster.metadata.AliasAction; +import org.elasticsearch.cluster.metadata.AliasOrIndex; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService; +import org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.shard.DocsStats; +import org.elasticsearch.index.store.StoreStats; +import org.elasticsearch.indices.IndexAlreadyExistsException; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; + +import java.util.List; + +/** + * Main class to swap the index pointed to by an alias, given some predicates + */ +public class TransportRolloverAction extends TransportMasterNodeAction { + + private final MetaDataCreateIndexService createIndexService; + private final MetaDataIndexAliasesService indexAliasesService; + private final Client client; + + @Inject + public TransportRolloverAction(Settings settings, TransportService transportService, ClusterService clusterService, + ThreadPool threadPool, MetaDataCreateIndexService createIndexService, + ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, + MetaDataIndexAliasesService indexAliasesService, Client client) { + super(settings, RolloverAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, + RolloverRequest::new); + this.createIndexService = createIndexService; + this.indexAliasesService = indexAliasesService; + this.client = client; + } + + @Override + protected String executor() { + // we go async right away + return ThreadPool.Names.SAME; + } + + @Override + protected RolloverResponse newResponse() { + return new RolloverResponse(); + } + + @Override + protected ClusterBlockException checkBlock(RolloverRequest request, ClusterState state) { + IndicesOptions indicesOptions = IndicesOptions.fromOptions(true, true, + request.indicesOptions().expandWildcardsOpen(), request.indicesOptions().expandWildcardsClosed()); + return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, + indexNameExpressionResolver.concreteIndexNames(state, indicesOptions, request.indices())); + } + + @Override + protected void masterOperation(final RolloverRequest rolloverRequest, final ClusterState state, + final ActionListener listener) { + final MetaData metaData = state.metaData(); + validate(metaData, rolloverRequest); + final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(rolloverRequest.getSourceAlias()); + final IndexMetaData indexMetaData = aliasOrIndex.getIndices().get(0); + final String sourceIndexName = indexMetaData.getIndex().getName(); + client.admin().indices().prepareStats(sourceIndexName).clear().setDocs(true).setStore(true) + .execute(new ActionListener() { + @Override + public void onResponse(IndicesStatsResponse indicesStatsResponse) { + final IndexMetaData sourceIndex = metaData.index(sourceIndexName); + DocsStats docsStats = indicesStatsResponse.getTotal().getDocs(); + long docCount = docsStats == null ? 0 : docsStats.getCount(); + StoreStats storeStats = indicesStatsResponse.getTotal().getStore(); + long sizeInBytes = storeStats == null ? 0 : storeStats.getSizeInBytes(); + long creationDate = sourceIndex.getCreationDate(); + if (satisfiesConditions(rolloverRequest.getConditions(), docCount, sizeInBytes, creationDate)) { + final String rolloverIndexName = generateRolloverIndexName(sourceIndexName); + boolean createRolloverIndex = metaData.index(rolloverIndexName) == null; + if (createRolloverIndex) { + CreateIndexClusterStateUpdateRequest updateRequest = + prepareCreateIndexRequest(rolloverIndexName, rolloverRequest); + createIndexService.createIndex(updateRequest, new ActionListener() { + @Override + public void onResponse(ClusterStateUpdateResponse response) { + indexAliasesService.indicesAliases( + prepareIndicesAliasesRequest(sourceIndexName, rolloverIndexName, rolloverRequest), + new IndicesAliasesListener(sourceIndexName, rolloverIndexName, listener)); + } + + @Override + public void onFailure(Throwable t) { + if (t instanceof IndexAlreadyExistsException) { + logger.trace("[{}] failed to create rollover index", t, updateRequest.index()); + } else { + logger.debug("[{}] failed to create rollover index", t, updateRequest.index()); + } + listener.onFailure(t); + } + }); + } else { + indexAliasesService.indicesAliases( + prepareIndicesAliasesRequest(sourceIndexName, rolloverIndexName, rolloverRequest), + new IndicesAliasesListener(sourceIndexName, rolloverIndexName, listener)); + } + } else { + // conditions not met + listener.onResponse(new RolloverResponse(sourceIndexName, sourceIndexName)); + } + } + + @Override + public void onFailure(Throwable e) { + listener.onFailure(e); + } + }); + + } + + private static final class IndicesAliasesListener implements ActionListener { + + private final ActionListener listener; + private final String oldIndex; + private final String newIndex; + + public IndicesAliasesListener(String oldIndex, String newIndex, ActionListener listener) { + this.oldIndex = oldIndex; + this.newIndex = newIndex; + this.listener = listener; + } + + @Override + public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { + listener.onResponse(new RolloverResponse(oldIndex, newIndex)); + } + + @Override + public void onFailure(Throwable e) { + listener.onFailure(e); + } + } + + static IndicesAliasesClusterStateUpdateRequest prepareIndicesAliasesRequest(String concreteSourceIndex, String targetIndex, + RolloverRequest request) { + final IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest() + .ackTimeout(request.ackTimeout()) + .masterNodeTimeout(request.masterNodeTimeout()); + final AliasAction[] actions; + if (request.getOptionalTargetAlias() != null) { + actions = new AliasAction[3]; + actions[0] = new AliasAction(AliasAction.Type.ADD, targetIndex, request.getSourceAlias()); + actions[1] = new AliasAction(AliasAction.Type.ADD, targetIndex, request.getOptionalTargetAlias()); + actions[2] = new AliasAction(AliasAction.Type.REMOVE, concreteSourceIndex, request.getSourceAlias()); + } else { + actions = new AliasAction[2]; + actions[0] = new AliasAction(AliasAction.Type.ADD, targetIndex, request.getSourceAlias()); + actions[1] = new AliasAction(AliasAction.Type.REMOVE, concreteSourceIndex, request.getSourceAlias()); + } + updateRequest.actions(actions); + return updateRequest; + } + + static String generateRolloverIndexName(String sourceIndexName) { + int numberIndex = sourceIndexName.lastIndexOf("-"); + int counter = 1; + String indexPrefix = sourceIndexName; + if (numberIndex != -1) { + try { + counter = Integer.parseInt(sourceIndexName.substring(numberIndex + 1)); + counter++; + indexPrefix = sourceIndexName.substring(0, numberIndex); + } catch (NumberFormatException ignored) { + } + } + return String.join("-", indexPrefix, String.valueOf(counter)); + } + + static boolean satisfiesConditions(List requestConditions, long docCount, long sizeInBytes, + long creationDate) { + for (Condition condition: requestConditions) { + switch (condition.getType()) { + case MAX_SIZE: + if (sizeInBytes < condition.getValue()) { + return false; + } + break; + case MAX_AGE: + long currentAge = System.currentTimeMillis() - creationDate; + if (currentAge < condition.getValue()) { + return false; + } + break; + case MAX_DOCS: + if (docCount < condition.getValue()) { + return false; + } + break; + } + } + return true; + } + + static void validate(MetaData metaData, RolloverRequest request) { + final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(request.getSourceAlias()); + if (aliasOrIndex == null) { + throw new IllegalArgumentException("source alias does not exist"); + } + if (aliasOrIndex.isAlias() == false) { + throw new IllegalArgumentException("source alias is a concrete index"); + } + if (aliasOrIndex.getIndices().size() != 1) { + throw new IllegalArgumentException("source alias maps to multiple indices"); + } + } + + static CreateIndexClusterStateUpdateRequest prepareCreateIndexRequest(final String targetIndexName, + final RolloverRequest rolloverRequest) { + return new CreateIndexClusterStateUpdateRequest(rolloverRequest, + "rollover_index", targetIndexName, true) + .ackTimeout(rolloverRequest.timeout()) + .masterNodeTimeout(rolloverRequest.masterNodeTimeout()); + } + +} diff --git a/core/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/core/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index 10275f22d66..24d190c68a1 100644 --- a/core/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/core/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -80,6 +80,9 @@ import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; +import org.elasticsearch.action.admin.indices.rollover.RolloverRequestBuilder; +import org.elasticsearch.action.admin.indices.rollover.RolloverResponse; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequestBuilder; @@ -800,4 +803,19 @@ public interface IndicesAdminClient extends ElasticsearchClient { */ void shrinkIndex(ShrinkRequest request, ActionListener listener); + /** + * Swaps the index pointed to by an alias given all provided conditions are satisfied + */ + RolloverRequestBuilder prepareRolloverIndex(String sourceAlias); + + /** + * Swaps the index pointed to by an alias given all provided conditions are satisfied + */ + ActionFuture rolloversIndex(RolloverRequest request); + + /** + * Swaps the index pointed to by an alias given all provided conditions are satisfied + */ + void rolloverIndex(RolloverRequest request, ActionListener listener); + } diff --git a/core/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/core/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 6481bec1b83..18a3a2ae202 100644 --- a/core/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/core/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -196,6 +196,10 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshAction; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.admin.indices.rollover.RolloverAction; +import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; +import org.elasticsearch.action.admin.indices.rollover.RolloverRequestBuilder; +import org.elasticsearch.action.admin.indices.rollover.RolloverResponse; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction; import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest; @@ -1704,6 +1708,21 @@ public abstract class AbstractClient extends AbstractComponent implements Client execute(ShrinkAction.INSTANCE, request, listener); } + @Override + public RolloverRequestBuilder prepareRolloverIndex(String sourceAlias) { + return new RolloverRequestBuilder(this, RolloverAction.INSTANCE).setSourceAlias(sourceAlias); + } + + @Override + public ActionFuture rolloversIndex(RolloverRequest request) { + return execute(RolloverAction.INSTANCE, request); + } + + @Override + public void rolloverIndex(RolloverRequest request, ActionListener listener) { + execute(RolloverAction.INSTANCE, request, listener); + } + @Override public ActionFuture getSettings(GetSettingsRequest request) { return execute(GetSettingsAction.INSTANCE, request); diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java index fd9191fd713..6d4f671c3ef 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java @@ -72,6 +72,7 @@ import org.elasticsearch.rest.action.admin.cluster.storedscripts.RestGetStoredSc import org.elasticsearch.rest.action.admin.cluster.storedscripts.RestPutSearchTemplateAction; import org.elasticsearch.rest.action.admin.cluster.storedscripts.RestPutStoredScriptAction; import org.elasticsearch.rest.action.admin.cluster.tasks.RestPendingClusterTasksAction; +import org.elasticsearch.rest.action.admin.indices.RestRolloverIndexAction; import org.elasticsearch.rest.action.admin.indices.RestShrinkIndexAction; import org.elasticsearch.rest.action.admin.indices.alias.RestIndicesAliasesAction; import org.elasticsearch.rest.action.admin.indices.alias.delete.RestIndexDeleteAliasesAction; @@ -211,6 +212,7 @@ public class NetworkModule extends AbstractModule { RestIndicesAliasesAction.class, RestCreateIndexAction.class, RestShrinkIndexAction.class, + RestRolloverIndexAction.class, RestDeleteIndexAction.class, RestCloseIndexAction.class, RestOpenIndexAction.class, diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java new file mode 100644 index 00000000000..42626b37281 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -0,0 +1,72 @@ +/* + * 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.rest.action.admin.indices; + +import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; +import org.elasticsearch.action.admin.indices.rollover.RolloverResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.BytesRestResponse; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestResponse; +import org.elasticsearch.rest.action.support.RestBuilderListener; + +import static org.elasticsearch.rest.RestStatus.OK; + +/** + * + */ +public class RestRolloverIndexAction extends BaseRestHandler { + + @Inject + public RestRolloverIndexAction(Settings settings, RestController controller, Client client) { + super(settings, client); + controller.registerHandler(RestRequest.Method.PUT, "/{alias}/_rollover/{optional_alias}", this); + controller.registerHandler(RestRequest.Method.POST, "/{alias}/_rollover/{optional_alias}", this); + } + + @Override + public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { + if (request.param("alias") == null) { + throw new IllegalArgumentException("no source alias"); + } + RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("alias"), request.param("optional_alias")); + if (request.hasContent()) { + rolloverIndexRequest.source(request.content()); + } + rolloverIndexRequest.timeout(request.paramAsTime("timeout", rolloverIndexRequest.timeout())); + rolloverIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", rolloverIndexRequest.masterNodeTimeout())); + client.admin().indices().rolloverIndex(rolloverIndexRequest, new RestBuilderListener(channel) { + @Override + public RestResponse buildResponse(RolloverResponse rolloverResponse, XContentBuilder builder) throws Exception { + builder.startObject(); + builder.field("old_index", rolloverResponse.getOldIndex()); + builder.field("new_index", rolloverResponse.getNewIndex()); + builder.endObject(); + return new BytesRestResponse(OK, builder); + } + }); + } +} diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java new file mode 100644 index 00000000000..f80543fd7c2 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java @@ -0,0 +1,105 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.action.admin.indices.alias.Alias; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.test.ESIntegTestCase; + +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.Matchers.equalTo; + +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST) +public class RolloverIT extends ESIntegTestCase { + + public void testRolloverOnEmptyIndex() throws Exception { + assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); + final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); + assertThat(response.getOldIndex(), equalTo("test_index")); + assertThat(response.getNewIndex(), equalTo("test_index-1")); + final ClusterState state = client().admin().cluster().prepareState().get().getState(); + final IndexMetaData oldIndex = state.metaData().index("test_index"); + assertFalse(oldIndex.getAliases().containsKey("test_alias")); + final IndexMetaData newIndex = state.metaData().index("test_index-1"); + assertTrue(newIndex.getAliases().containsKey("test_alias")); + } + + public void testRollover() throws Exception { + assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); + index("test_index", "type1", "1", "field", "value"); + flush("test_index"); + final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); + assertThat(response.getOldIndex(), equalTo("test_index")); + assertThat(response.getNewIndex(), equalTo("test_index-1")); + final ClusterState state = client().admin().cluster().prepareState().get().getState(); + final IndexMetaData oldIndex = state.metaData().index("test_index"); + assertFalse(oldIndex.getAliases().containsKey("test_alias")); + final IndexMetaData newIndex = state.metaData().index("test_index-1"); + assertTrue(newIndex.getAliases().containsKey("test_alias")); + } + + public void testRolloverConditionsNotMet() throws Exception { + assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); + index("test_index", "type1", "1", "field", "value"); + flush("test_index"); + final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias") + .addMaxIndexAgeCondition("7d").get(); + assertThat(response.getOldIndex(), equalTo("test_index")); + assertThat(response.getNewIndex(), equalTo("test_index")); + final ClusterState state = client().admin().cluster().prepareState().get().getState(); + final IndexMetaData oldIndex = state.metaData().index("test_index"); + assertTrue(oldIndex.getAliases().containsKey("test_alias")); + final IndexMetaData newIndex = state.metaData().index("test_index-1"); + assertNull(newIndex); + } + + public void testRolloverWithOptionalTargetAlias() throws Exception { + assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); + index("test_index", "type1", "1", "field", "value"); + flush("test_index"); + final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias") + .setOptionalTargetAlias("test_alias_2").get(); + assertThat(response.getOldIndex(), equalTo("test_index")); + assertThat(response.getNewIndex(), equalTo("test_index-1")); + final ClusterState state = client().admin().cluster().prepareState().get().getState(); + final IndexMetaData oldIndex = state.metaData().index("test_index"); + assertFalse(oldIndex.getAliases().containsKey("test_alias")); + final IndexMetaData newIndex = state.metaData().index("test_index-1"); + assertTrue(newIndex.getAliases().containsKey("test_alias")); + assertTrue(newIndex.getAliases().containsKey("test_alias_2")); + } + + public void testRolloverOnExistingIndex() throws Exception { + assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); + index("test_index", "type1", "1", "field", "value"); + assertAcked(prepareCreate("test_index-1").get()); + index("test_index-1", "type1", "1", "field", "value"); + flush("test_index", "test_index-1"); + final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); + assertThat(response.getOldIndex(), equalTo("test_index")); + assertThat(response.getNewIndex(), equalTo("test_index-1")); + final ClusterState state = client().admin().cluster().prepareState().get().getState(); + final IndexMetaData oldIndex = state.metaData().index("test_index"); + assertFalse(oldIndex.getAliases().containsKey("test_alias")); + final IndexMetaData newIndex = state.metaData().index("test_index-1"); + assertTrue(newIndex.getAliases().containsKey("test_alias")); + } +} diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java new file mode 100644 index 00000000000..959f0d81bf0 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java @@ -0,0 +1,192 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.Version; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest; +import org.elasticsearch.cluster.metadata.AliasAction; +import org.elasticsearch.cluster.metadata.AliasMetaData; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.UUIDs; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ESTestCase; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; + +public class TransportRolloverActionTests extends ESTestCase { + + public void testSatisfyConditions() throws Exception { + List conditions = Collections.emptyList(); + assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomLong(), + randomLong())); + + conditions = Collections.singletonList( + new Condition(Condition.ConditionType.MAX_AGE, 10L)); + assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomLong(), + System.currentTimeMillis() - randomIntBetween(10, 100))); + assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomLong(), + System.currentTimeMillis() - randomIntBetween(1, 9))); + + conditions = Collections.singletonList( + new Condition(Condition.ConditionType.MAX_SIZE, 10L)); + assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomIntBetween(10, 100), + randomLong())); + assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomIntBetween(1, 9), + randomLong())); + + conditions = Collections.singletonList( + new Condition(Condition.ConditionType.MAX_DOCS, 10L)); + assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(10, 100), randomLong(), + randomLong())); + assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1, 9), randomLong(), + randomLong())); + + conditions = Arrays.asList(new Condition(Condition.ConditionType.MAX_AGE, 100L), + new Condition(Condition.ConditionType.MAX_DOCS, 1000L)); + assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1000, 1500), + randomLong(), System.currentTimeMillis() - randomIntBetween(100, 500))); + assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1, 999), + randomLong(), System.currentTimeMillis() - randomIntBetween(100, 500))); + assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1000, 1500), + randomLong(), System.currentTimeMillis() - randomIntBetween(1, 99))); + } + + public void testCreateUpdateAliasRequest() throws Exception { + String sourceAlias = randomAsciiOfLength(10); + String sourceIndex = randomAsciiOfLength(10); + String targetIndex = randomAsciiOfLength(10); + final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, null); + final IndicesAliasesClusterStateUpdateRequest updateRequest = + TransportRolloverAction.prepareIndicesAliasesRequest(sourceIndex, targetIndex, rolloverRequest); + + final AliasAction[] actions = updateRequest.actions(); + assertThat(actions.length, equalTo(2)); + boolean foundAdd = false; + boolean foundRemove = false; + for (AliasAction action : actions) { + if (action.actionType() == AliasAction.Type.ADD) { + foundAdd = true; + assertThat(action.index(), equalTo(targetIndex)); + assertThat(action.alias(), equalTo(sourceAlias)); + } else if (action.actionType() == AliasAction.Type.REMOVE) { + foundRemove = true; + assertThat(action.index(), equalTo(sourceIndex)); + assertThat(action.alias(), equalTo(sourceAlias)); + } + } + assertTrue(foundAdd); + assertTrue(foundRemove); + } + + public void testCreateUpdateAliasRequestWithOptionalTargetAlias() throws Exception { + String sourceAlias = randomAsciiOfLength(10); + String optionalTargetAlias = randomAsciiOfLength(10); + String sourceIndex = randomAsciiOfLength(10); + String targetIndex = randomAsciiOfLength(10); + final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, optionalTargetAlias); + final IndicesAliasesClusterStateUpdateRequest updateRequest = + TransportRolloverAction.prepareIndicesAliasesRequest(sourceIndex, targetIndex, rolloverRequest); + + final AliasAction[] actions = updateRequest.actions(); + assertThat(actions.length, equalTo(3)); + boolean foundAdd = false; + boolean foundRemove = false; + for (AliasAction action : actions) { + if (action.actionType() == AliasAction.Type.ADD) { + foundAdd = true; + assertThat(action.index(), equalTo(targetIndex)); + assertThat(action.alias(), anyOf(equalTo(sourceAlias), + equalTo(optionalTargetAlias))); + } else if (action.actionType() == AliasAction.Type.REMOVE) { + foundRemove = true; + assertThat(action.index(), equalTo(sourceIndex)); + assertThat(action.alias(), equalTo(sourceAlias)); + } + } + assertTrue(foundAdd); + assertTrue(foundRemove); + } + + public void testValidation() throws Exception { + String index1 = randomAsciiOfLength(10); + String alias = randomAsciiOfLength(10); + String index2 = randomAsciiOfLength(10); + String aliasWithMultipleIndices = randomAsciiOfLength(10); + final Settings settings = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .build(); + final MetaData metaData = MetaData.builder() + .put(IndexMetaData.builder(index1) + .settings(settings) + .putAlias(AliasMetaData.builder(alias)) + .putAlias(AliasMetaData.builder(aliasWithMultipleIndices)) + ) + .put(IndexMetaData.builder(index2) + .settings(settings) + .putAlias(AliasMetaData.builder(aliasWithMultipleIndices)) + ).build(); + + try { + TransportRolloverAction.validate(metaData, new RolloverRequest(aliasWithMultipleIndices, + randomBoolean() ? null : randomAsciiOfLength(10))); + fail("expected to throw exception"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("source alias maps to multiple indices")); + } + + try { + TransportRolloverAction.validate(metaData, new RolloverRequest(randomFrom(index1, index2), + randomBoolean() ? null : randomAsciiOfLength(10))); + fail("expected to throw exception"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("source alias is a concrete index")); + } + + try { + TransportRolloverAction.validate(metaData, new RolloverRequest(randomAsciiOfLength(5), + randomBoolean() ? null : randomAsciiOfLength(10))); + fail("expected to throw exception"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), equalTo("source alias does not exist")); + } + + TransportRolloverAction.validate(metaData, new RolloverRequest(alias, + randomBoolean() ? null : randomAsciiOfLength(10))); + } + + public void testGenerateRolloverIndexName() throws Exception { + String index = randomAsciiOfLength(10); + assertThat(TransportRolloverAction.generateRolloverIndexName(index), not(equalTo(index))); + assertThat(TransportRolloverAction.generateRolloverIndexName("index"), equalTo("index-1")); + assertThat(TransportRolloverAction.generateRolloverIndexName("index-1"), equalTo("index-2")); + assertThat(TransportRolloverAction.generateRolloverIndexName("index-name-1"), equalTo("index-name-2")); + assertThat(TransportRolloverAction.generateRolloverIndexName("index-name"), equalTo("index-name-1")); + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json new file mode 100644 index 00000000000..494ff408273 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json @@ -0,0 +1,35 @@ +{ + "indices.rollover": { + "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html", + "methods": ["PUT", "POST"], + "url": { + "path": "/{alias}/_rollover/{target_alias}", + "paths": ["/{alias}/_rollover/{target_alias}"], + "parts": { + "alias": { + "type" : "string", + "required" : true, + "description" : "The name of the alias to rollover" + }, + "target_alias": { + "type" : "string", + "required" : false, + "description" : "The name of optional target alias" + } + }, + "params": { + "timeout": { + "type" : "time", + "description" : "Explicit operation timeout" + }, + "master_timeout": { + "type" : "time", + "description" : "Specify timeout for connection to master" + } + } + }, + "body": { + "description" : "The conditions that needs to be met for executing rollover" + } + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml new file mode 100644 index 00000000000..a9acf8d150a --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml @@ -0,0 +1,69 @@ +--- +"Rollover index via API": + # create index with alias + - do: + indices.create: + index: logs + body: + settings: + number_of_replicas: "0" + aliases: + logs_index: {} + logs_search: {} + + # index document + - do: + index: + index: logs + type: test + id: "1" + body: { "foo": "hello world" } + + - do: + get: + index: logs_search + type: test + id: "1" + + - match: { _index: logs } + - match: { _type: test } + - match: { _id: "1" } + - match: { _source: { foo: "hello world" } } + + # perform alias rollover + - do: + indices.rollover: + alias: "logs_search" + body: + condition.max_docs: 1 + + - match: { old_index: logs } + - match: { new_index: logs-1 } + + # ensure new index is created + - do: + indices.exists: + index: logs-1 + + - is_true: '' + + # index into new index + - do: + index: + index: logs-1 + type: test + id: "2" + body: { "foo": "hello world" } + + # check alias points to the new index + - do: + get: + index: logs_search + type: test + id: "2" + + - match: { _index: logs-1 } + - match: { _type: test } + - match: { _id: "2" } + - match: { _source: { foo: "hello world" } } + From 3a2cc22afffb2af453dfec785e062f19de9d1804 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Mon, 6 Jun 2016 16:10:36 -0400 Subject: [PATCH 08/87] simplify conditions and rollover request --- .../admin/indices/rollover/Condition.java | 121 +++++++-------- .../indices/rollover/RolloverRequest.java | 76 +++------- .../rollover/RolloverRequestBuilder.java | 15 +- .../rollover/TransportRolloverAction.java | 142 ++++++++---------- .../indices/RestRolloverIndexAction.java | 6 +- 5 files changed, 153 insertions(+), 207 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java index c5ef9b4c51b..bd70dda62fc 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java @@ -19,87 +19,82 @@ package org.elasticsearch.action.admin.indices.rollover; -import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; +import org.elasticsearch.common.io.stream.NamedWriteable; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.ObjectParser; -import java.util.Locale; +import java.io.IOException; +import java.util.Set; -public class Condition { +public abstract class Condition implements NamedWriteable { + public static ObjectParser, ParseFieldMatcherSupplier> PARSER = + new ObjectParser<>("conditions", null); + static { + PARSER.declareString((conditions, s) -> + conditions.add(new MaxAge(TimeValue.parseTimeValue(s, MaxAge.NAME))), new ParseField(MaxAge.NAME)); + PARSER.declareLong((conditions, value) -> + conditions.add(new MaxDocs(value)), new ParseField(MaxDocs.NAME)); + } - public enum ConditionType { - MAX_SIZE((byte) 0), - MAX_AGE((byte) 1), - MAX_DOCS((byte) 2); + public static class MaxAge extends Condition { + public final static String NAME = "max_age"; - private final byte id; - - ConditionType(byte id) { - this.id = id; + public MaxAge(TimeValue value) { + this.value = value; } - public byte getId() { - return id; + public MaxAge(StreamInput in) throws IOException { + this.value = TimeValue.timeValueMillis(in.readLong()); } - public static ConditionType fromId(byte id) { - if (id == 0) { - return MAX_SIZE; - } else if (id == 1) { - return MAX_AGE; - } else if (id == 2) { - return MAX_DOCS; - } else { - throw new IllegalArgumentException("no condition type [" + id + "]"); - } + @Override + public boolean matches(TimeValue value) { + return this.value.getMillis() <= value.getMillis(); } - public static ConditionType fromString(String type) { - final String typeString = type.toLowerCase(Locale.ROOT); - switch (typeString) { - case "max_size": - return MAX_SIZE; - case "max_age": - return MAX_AGE; - case "max_docs": - return MAX_DOCS; - default: - throw new IllegalArgumentException("no condition type [" + type + "]"); - } + @Override + public String getWriteableName() { + return NAME; } - public static long parseFromString(ConditionType condition, String value) { - switch (condition) { - case MAX_SIZE: - return ByteSizeValue.parseBytesSizeValue(value, MAX_SIZE.name().toLowerCase(Locale.ROOT)).getBytes(); - case MAX_AGE: - return TimeValue.parseTimeValue(value, MAX_AGE.name().toLowerCase(Locale.ROOT)).getMillis(); - case MAX_DOCS: - try { - return Long.valueOf(value); - } catch (NumberFormatException e) { - throw new ElasticsearchParseException("Failed to parse setting [{}] with value [{}] as long", e, - MAX_DOCS.name().toLowerCase(Locale.ROOT), value); - } - default: - throw new ElasticsearchParseException("condition [" + condition + "] not recognized"); - } + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeLong(value.getMillis()); } } - private final ConditionType type; - private final long value; + public static class MaxDocs extends Condition { + public final static String NAME = "max_docs"; - public Condition(ConditionType type, long value) { - this.type = type; - this.value = value; + public MaxDocs(Long value) { + this.value = value; + } + + public MaxDocs(StreamInput in) throws IOException { + this.value = in.readLong(); + } + + @Override + public boolean matches(Long value) { + return this.value <= value; + } + + @Override + public String getWriteableName() { + return NAME; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeLong(value); + } } - public ConditionType getType() { - return type; - } + protected T value; - public long getValue() { - return value; - } + public abstract boolean matches(T value); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index 4a233bf2d81..03c288f53dd 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -23,17 +23,21 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.AcknowledgedRequest; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -44,14 +48,20 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; public class RolloverRequest extends AcknowledgedRequest implements IndicesRequest { private String sourceAlias; - private String optionalTargetAlias; - private List conditions = new ArrayList<>(); + private Set conditions = new HashSet<>(2); + + public static ObjectParser, ParseFieldMatcherSupplier> TLP_PARSER = + new ObjectParser<>("conditions", null); + static { + TLP_PARSER.declareField((parser, conditions, parseFieldMatcherSupplier) -> + Condition.PARSER.parse(parser, conditions, () -> ParseFieldMatcher.EMPTY), + new ParseField("conditions"), ObjectParser.ValueType.OBJECT); + } RolloverRequest() {} - public RolloverRequest(String sourceAlias, String optionalTargetAlias) { + public RolloverRequest(String sourceAlias) { this.sourceAlias = sourceAlias; - this.optionalTargetAlias = optionalTargetAlias; } @Override @@ -67,12 +77,9 @@ public class RolloverRequest extends AcknowledgedRequest implem public void readFrom(StreamInput in) throws IOException { super.readFrom(in); sourceAlias = in.readString(); - optionalTargetAlias = in.readOptionalString(); int size = in.readVInt(); for (int i = 0; i < size; i++) { - Condition.ConditionType type = Condition.ConditionType.fromId(in.readByte()); - long value = in.readLong(); - this.conditions.add(new Condition(type, value)); + this.conditions.add(in.readNamedWriteable(Condition.class)); } } @@ -80,11 +87,9 @@ public class RolloverRequest extends AcknowledgedRequest implem public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(sourceAlias); - out.writeOptionalString(optionalTargetAlias); out.writeVInt(conditions.size()); for (Condition condition : conditions) { - out.writeByte(condition.getType().getId()); - out.writeLong(condition.getValue()); + out.writeNamedWriteable(condition); } } @@ -102,27 +107,15 @@ public class RolloverRequest extends AcknowledgedRequest implem this.sourceAlias = sourceAlias; } - public void setOptionalTargetAlias(String optionalTargetAlias) { - this.optionalTargetAlias = optionalTargetAlias; + public void addMaxIndexAgeCondition(TimeValue age) { + this.conditions.add(new Condition.MaxAge(age)); } - public void addMaxIndexAgeCondition(String age) { - addCondition(Condition.ConditionType.MAX_AGE, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_AGE, age)); + public void addMaxIndexDocsCondition(long docs) { + this.conditions.add(new Condition.MaxDocs(docs)); } - public void addMaxIndexDocsCondition(String docs) { - addCondition(Condition.ConditionType.MAX_DOCS, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_DOCS, docs)); - } - - public void addMaxIndexSizeCondition(String size) { - addCondition(Condition.ConditionType.MAX_SIZE, Condition.ConditionType.parseFromString(Condition.ConditionType.MAX_SIZE, size)); - } - - private void addCondition(Condition.ConditionType conditionType, long value) { - this.conditions.add(new Condition(conditionType, value)); - } - - public List getConditions() { + public Set getConditions() { return conditions; } @@ -130,15 +123,11 @@ public class RolloverRequest extends AcknowledgedRequest implem return sourceAlias; } - public String getOptionalTargetAlias() { - return optionalTargetAlias; - } - public void source(BytesReference source) { XContentType xContentType = XContentFactory.xContentType(source); if (xContentType != null) { try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(source)) { - source(parser.map()); + TLP_PARSER.parse(parser, this.conditions, () -> ParseFieldMatcher.EMPTY); } catch (IOException e) { throw new ElasticsearchParseException("failed to parse source for rollover index", e); } @@ -146,19 +135,4 @@ public class RolloverRequest extends AcknowledgedRequest implem throw new ElasticsearchParseException("failed to parse content type for rollover index source"); } } - - private void source(Map map) { - for (Map.Entry entry : map.entrySet()) { - if (entry.getKey().equals("conditions")) { - final Map conditions = (Map) entry.getValue(); - for (Map.Entry conditionEntry : conditions.entrySet()) { - final Condition.ConditionType conditionType = Condition.ConditionType.fromString(conditionEntry.getKey()); - this.addCondition(conditionType, Condition.ConditionType.parseFromString(conditionType, - conditionEntry.getValue())); - } - } else { - throw new ElasticsearchParseException("unknown property [" + entry.getKey() + "]"); - } - } - } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java index c42bb9cbd83..2a95468de69 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.admin.indices.rollover; import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; +import org.elasticsearch.common.unit.TimeValue; /** @@ -36,22 +37,12 @@ public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder() { - @Override - public void onResponse(IndicesStatsResponse indicesStatsResponse) { - final IndexMetaData sourceIndex = metaData.index(sourceIndexName); - DocsStats docsStats = indicesStatsResponse.getTotal().getDocs(); - long docCount = docsStats == null ? 0 : docsStats.getCount(); - StoreStats storeStats = indicesStatsResponse.getTotal().getStore(); - long sizeInBytes = storeStats == null ? 0 : storeStats.getSizeInBytes(); - long creationDate = sourceIndex.getCreationDate(); - if (satisfiesConditions(rolloverRequest.getConditions(), docCount, sizeInBytes, creationDate)) { - final String rolloverIndexName = generateRolloverIndexName(sourceIndexName); - boolean createRolloverIndex = metaData.index(rolloverIndexName) == null; - if (createRolloverIndex) { - CreateIndexClusterStateUpdateRequest updateRequest = - prepareCreateIndexRequest(rolloverIndexName, rolloverRequest); - createIndexService.createIndex(updateRequest, new ActionListener() { - @Override - public void onResponse(ClusterStateUpdateResponse response) { - indexAliasesService.indicesAliases( - prepareIndicesAliasesRequest(sourceIndexName, rolloverIndexName, rolloverRequest), - new IndicesAliasesListener(sourceIndexName, rolloverIndexName, listener)); - } - - @Override - public void onFailure(Throwable t) { - if (t instanceof IndexAlreadyExistsException) { - logger.trace("[{}] failed to create rollover index", t, updateRequest.index()); - } else { - logger.debug("[{}] failed to create rollover index", t, updateRequest.index()); + client.admin().indices().prepareStats(sourceIndexName).clear().setDocs(true).execute( + new ActionListener() { + @Override + public void onResponse(IndicesStatsResponse indicesStatsResponse) { + final IndexMetaData sourceIndex = metaData.index(sourceIndexName); + DocsStats docsStats = indicesStatsResponse.getTotal().getDocs(); + long docCount = docsStats == null ? 0 : docsStats.getCount(); + long indexAge = System.currentTimeMillis() - sourceIndex.getCreationDate(); + if (satisfiesConditions(rolloverRequest.getConditions(), docCount, indexAge)) { + final String rolloverIndexName = generateRolloverIndexName(sourceIndexName); + boolean createRolloverIndex = metaData.index(rolloverIndexName) == null; + if (createRolloverIndex) { + CreateIndexClusterStateUpdateRequest updateRequest = + prepareCreateIndexRequest(rolloverIndexName, rolloverRequest); + createIndexService.createIndex(updateRequest, new ActionListener() { + @Override + public void onResponse(ClusterStateUpdateResponse response) { + indexAliasesService.indicesAliases( + prepareIndicesAliasesRequest(sourceIndexName, rolloverIndexName, rolloverRequest), + new IndicesAliasesListener(sourceIndexName, rolloverIndexName, listener)); } - listener.onFailure(t); - } - }); + + @Override + public void onFailure(Throwable t) { + if (t instanceof IndexAlreadyExistsException) { + logger.trace("[{}] failed to create rollover index", t, updateRequest.index()); + } else { + logger.debug("[{}] failed to create rollover index", t, updateRequest.index()); + } + listener.onFailure(t); + } + }); + } else { + indexAliasesService.indicesAliases( + prepareIndicesAliasesRequest(sourceIndexName, rolloverIndexName, rolloverRequest), + new IndicesAliasesListener(sourceIndexName, rolloverIndexName, listener)); + } } else { - indexAliasesService.indicesAliases( - prepareIndicesAliasesRequest(sourceIndexName, rolloverIndexName, rolloverRequest), - new IndicesAliasesListener(sourceIndexName, rolloverIndexName, listener)); + // conditions not met + listener.onResponse(new RolloverResponse(sourceIndexName, sourceIndexName)); } - } else { - // conditions not met - listener.onResponse(new RolloverResponse(sourceIndexName, sourceIndexName)); + } + + @Override + public void onFailure(Throwable e) { + listener.onFailure(e); } } - - @Override - public void onFailure(Throwable e) { - listener.onFailure(e); - } - }); + ); } @@ -178,17 +177,9 @@ public class TransportRolloverAction extends TransportMasterNodeAction requestConditions, long docCount, long sizeInBytes, - long creationDate) { - for (Condition condition: requestConditions) { - switch (condition.getType()) { - case MAX_SIZE: - if (sizeInBytes < condition.getValue()) { - return false; - } - break; - case MAX_AGE: - long currentAge = System.currentTimeMillis() - creationDate; - if (currentAge < condition.getValue()) { - return false; - } - break; - case MAX_DOCS: - if (docCount < condition.getValue()) { - return false; - } - break; + static boolean satisfiesConditions(Set conditions, long docCount, long indexAge) { + for (Condition condition: conditions) { + if (condition instanceof Condition.MaxAge) { + Condition.MaxAge maxAge = (Condition.MaxAge) condition; + final TimeValue age = TimeValue.timeValueMillis(indexAge); + if (maxAge.matches(age) == false) { + return false; + } + } else if (condition instanceof Condition.MaxDocs) { + final Condition.MaxDocs maxDocs = (Condition.MaxDocs) condition; + if (maxDocs.matches(docCount) == false) { + return false; + } + } else { + throw new IllegalArgumentException("unknown condition [" + condition.getClass().getSimpleName() + "]"); } } return true; diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index 42626b37281..50ec45e9229 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -43,8 +43,8 @@ public class RestRolloverIndexAction extends BaseRestHandler { @Inject public RestRolloverIndexAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(RestRequest.Method.PUT, "/{alias}/_rollover/{optional_alias}", this); - controller.registerHandler(RestRequest.Method.POST, "/{alias}/_rollover/{optional_alias}", this); + controller.registerHandler(RestRequest.Method.PUT, "/{alias}/_rollover", this); + controller.registerHandler(RestRequest.Method.POST, "/{alias}/_rollover", this); } @Override @@ -52,7 +52,7 @@ public class RestRolloverIndexAction extends BaseRestHandler { if (request.param("alias") == null) { throw new IllegalArgumentException("no source alias"); } - RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("alias"), request.param("optional_alias")); + RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("alias")); if (request.hasContent()) { rolloverIndexRequest.source(request.content()); } From d96fe20e3a45d3d891d39967d22abeecac8a7452 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Mon, 6 Jun 2016 16:11:46 -0400 Subject: [PATCH 09/87] add named writable registry glue --- .../elasticsearch/indices/IndicesModule.java | 12 ++- .../java/org/elasticsearch/node/Node.java | 2 +- .../admin/indices/rollover/RolloverIT.java | 19 +--- .../TransportRolloverActionTests.java | 87 +++++-------------- .../elasticsearch/index/IndexModuleTests.java | 3 +- .../index/engine/InternalEngineTests.java | 3 +- .../internal/FieldNamesFieldMapperTests.java | 3 +- .../aggregations/AggregatorParsingTests.java | 2 +- .../aggregations/BaseAggregationTestCase.java | 2 +- .../BasePipelineAggregationTestCase.java | 2 +- .../builder/SearchSourceBuilderTests.java | 2 +- .../messy/tests/TemplateQueryParserTests.java | 2 +- .../attachments/AttachmentUnitTestCase.java | 3 +- .../index/mapper/size/SizeMappingTests.java | 3 +- .../rest-api-spec/api/indices.rollover.json | 9 +- .../elasticsearch/index/MapperTestUtils.java | 3 +- .../test/AbstractQueryTestCase.java | 2 +- 17 files changed, 56 insertions(+), 103 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesModule.java b/core/src/main/java/org/elasticsearch/indices/IndicesModule.java index 8cedea931c0..885e2d78eca 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesModule.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesModule.java @@ -19,10 +19,12 @@ package org.elasticsearch.indices; +import org.elasticsearch.action.admin.indices.rollover.Condition; import org.elasticsearch.action.update.UpdateHelper; import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService; import org.elasticsearch.common.geo.ShapesAvailability; import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.index.NodeServicesProvider; import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.index.mapper.MetadataFieldMapper; @@ -74,10 +76,18 @@ public class IndicesModule extends AbstractModule { // Use a LinkedHashMap for metadataMappers because iteration order matters private final Map metadataMapperParsers = new LinkedHashMap<>(); + private final NamedWriteableRegistry namedWritableRegistry; - public IndicesModule() { + public IndicesModule(NamedWriteableRegistry namedWriteableRegistry) { + this.namedWritableRegistry = namedWriteableRegistry; registerBuiltInMappers(); registerBuiltInMetadataMappers(); + registerBuildInWritables(); + } + + private void registerBuildInWritables() { + namedWritableRegistry.register(Condition.class, Condition.MaxAge.NAME, Condition.MaxAge::new); + namedWritableRegistry.register(Condition.class, Condition.MaxDocs.NAME, Condition.MaxDocs::new); } private void registerBuiltInMappers() { diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index cf33770fd16..ad287549931 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -235,7 +235,7 @@ public class Node implements Closeable { modules.add(new ThreadPoolModule(threadPool)); modules.add(new DiscoveryModule(this.settings)); modules.add(new ClusterModule(this.settings)); - modules.add(new IndicesModule()); + modules.add(new IndicesModule(namedWriteableRegistry)); modules.add(new SearchModule(settings, namedWriteableRegistry)); modules.add(new ActionModule(DiscoveryNode.isIngestNode(settings), false)); modules.add(new GatewayModule(settings)); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java index f80543fd7c2..3ab9c8cc040 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java @@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.indices.rollover; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESIntegTestCase; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -61,7 +62,7 @@ public class RolloverIT extends ESIntegTestCase { index("test_index", "type1", "1", "field", "value"); flush("test_index"); final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias") - .addMaxIndexAgeCondition("7d").get(); + .addMaxIndexAgeCondition(TimeValue.timeValueHours(4)).get(); assertThat(response.getOldIndex(), equalTo("test_index")); assertThat(response.getNewIndex(), equalTo("test_index")); final ClusterState state = client().admin().cluster().prepareState().get().getState(); @@ -71,22 +72,6 @@ public class RolloverIT extends ESIntegTestCase { assertNull(newIndex); } - public void testRolloverWithOptionalTargetAlias() throws Exception { - assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); - index("test_index", "type1", "1", "field", "value"); - flush("test_index"); - final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias") - .setOptionalTargetAlias("test_alias_2").get(); - assertThat(response.getOldIndex(), equalTo("test_index")); - assertThat(response.getNewIndex(), equalTo("test_index-1")); - final ClusterState state = client().admin().cluster().prepareState().get().getState(); - final IndexMetaData oldIndex = state.metaData().index("test_index"); - assertFalse(oldIndex.getAliases().containsKey("test_alias")); - final IndexMetaData newIndex = state.metaData().index("test_index-1"); - assertTrue(newIndex.getAliases().containsKey("test_alias")); - assertTrue(newIndex.getAliases().containsKey("test_alias_2")); - } - public void testRolloverOnExistingIndex() throws Exception { assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); index("test_index", "type1", "1", "field", "value"); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java index 959f0d81bf0..ff121ff3dfb 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java @@ -27,59 +27,49 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.test.ESTestCase; -import java.util.Arrays; import java.util.Collections; -import java.util.List; +import java.util.Set; -import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; public class TransportRolloverActionTests extends ESTestCase { public void testSatisfyConditions() throws Exception { - List conditions = Collections.emptyList(); - assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomLong(), + Set conditions = Collections.emptySet(); + assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomLong())); - conditions = Collections.singletonList( - new Condition(Condition.ConditionType.MAX_AGE, 10L)); - assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomLong(), - System.currentTimeMillis() - randomIntBetween(10, 100))); - assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomLong(), - System.currentTimeMillis() - randomIntBetween(1, 9))); + conditions = Collections.singleton(new Condition.MaxAge(TimeValue.timeValueMillis(10))); + assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), + TimeValue.timeValueMillis(randomIntBetween(10, 100)).getMillis())); + assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), + TimeValue.timeValueMillis(randomIntBetween(0, 9)).getMillis())); - conditions = Collections.singletonList( - new Condition(Condition.ConditionType.MAX_SIZE, 10L)); - assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomIntBetween(10, 100), + conditions = Collections.singleton(new Condition.MaxDocs(10L)); + assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(10, 100), randomLong())); - assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), randomIntBetween(1, 9), + assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1, 9), randomLong())); - conditions = Collections.singletonList( - new Condition(Condition.ConditionType.MAX_DOCS, 10L)); - assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(10, 100), randomLong(), - randomLong())); - assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1, 9), randomLong(), - randomLong())); - - conditions = Arrays.asList(new Condition(Condition.ConditionType.MAX_AGE, 100L), - new Condition(Condition.ConditionType.MAX_DOCS, 1000L)); + conditions = Sets.newHashSet(new Condition.MaxAge(TimeValue.timeValueMillis(100)), new Condition.MaxDocs(1000L)); assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1000, 1500), - randomLong(), System.currentTimeMillis() - randomIntBetween(100, 500))); + TimeValue.timeValueMillis(randomIntBetween(100, 1000)).getMillis())); assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1, 999), - randomLong(), System.currentTimeMillis() - randomIntBetween(100, 500))); + TimeValue.timeValueMillis(randomIntBetween(100, 1000)).getMillis())); assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1000, 1500), - randomLong(), System.currentTimeMillis() - randomIntBetween(1, 99))); + TimeValue.timeValueMillis(randomIntBetween(0, 99)).getMillis())); } public void testCreateUpdateAliasRequest() throws Exception { String sourceAlias = randomAsciiOfLength(10); String sourceIndex = randomAsciiOfLength(10); String targetIndex = randomAsciiOfLength(10); - final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, null); + final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias); final IndicesAliasesClusterStateUpdateRequest updateRequest = TransportRolloverAction.prepareIndicesAliasesRequest(sourceIndex, targetIndex, rolloverRequest); @@ -102,35 +92,6 @@ public class TransportRolloverActionTests extends ESTestCase { assertTrue(foundRemove); } - public void testCreateUpdateAliasRequestWithOptionalTargetAlias() throws Exception { - String sourceAlias = randomAsciiOfLength(10); - String optionalTargetAlias = randomAsciiOfLength(10); - String sourceIndex = randomAsciiOfLength(10); - String targetIndex = randomAsciiOfLength(10); - final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, optionalTargetAlias); - final IndicesAliasesClusterStateUpdateRequest updateRequest = - TransportRolloverAction.prepareIndicesAliasesRequest(sourceIndex, targetIndex, rolloverRequest); - - final AliasAction[] actions = updateRequest.actions(); - assertThat(actions.length, equalTo(3)); - boolean foundAdd = false; - boolean foundRemove = false; - for (AliasAction action : actions) { - if (action.actionType() == AliasAction.Type.ADD) { - foundAdd = true; - assertThat(action.index(), equalTo(targetIndex)); - assertThat(action.alias(), anyOf(equalTo(sourceAlias), - equalTo(optionalTargetAlias))); - } else if (action.actionType() == AliasAction.Type.REMOVE) { - foundRemove = true; - assertThat(action.index(), equalTo(sourceIndex)); - assertThat(action.alias(), equalTo(sourceAlias)); - } - } - assertTrue(foundAdd); - assertTrue(foundRemove); - } - public void testValidation() throws Exception { String index1 = randomAsciiOfLength(10); String alias = randomAsciiOfLength(10); @@ -154,31 +115,27 @@ public class TransportRolloverActionTests extends ESTestCase { ).build(); try { - TransportRolloverAction.validate(metaData, new RolloverRequest(aliasWithMultipleIndices, - randomBoolean() ? null : randomAsciiOfLength(10))); + TransportRolloverAction.validate(metaData, new RolloverRequest(aliasWithMultipleIndices)); fail("expected to throw exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), equalTo("source alias maps to multiple indices")); } try { - TransportRolloverAction.validate(metaData, new RolloverRequest(randomFrom(index1, index2), - randomBoolean() ? null : randomAsciiOfLength(10))); + TransportRolloverAction.validate(metaData, new RolloverRequest(randomFrom(index1, index2))); fail("expected to throw exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), equalTo("source alias is a concrete index")); } try { - TransportRolloverAction.validate(metaData, new RolloverRequest(randomAsciiOfLength(5), - randomBoolean() ? null : randomAsciiOfLength(10))); + TransportRolloverAction.validate(metaData, new RolloverRequest(randomAsciiOfLength(5))); fail("expected to throw exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), equalTo("source alias does not exist")); } - TransportRolloverAction.validate(metaData, new RolloverRequest(alias, - randomBoolean() ? null : randomAsciiOfLength(10))); + TransportRolloverAction.validate(metaData, new RolloverRequest(alias)); } public void testGenerateRolloverIndexName() throws Exception { diff --git a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java index 38b7341cd24..6078b0a8a17 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java @@ -35,6 +35,7 @@ import org.elasticsearch.Version; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; @@ -134,7 +135,7 @@ public class IndexModuleTests extends ESTestCase { environment = new Environment(settings); nodeServicesProvider = newNodeServiceProvider(settings, environment, null); nodeEnvironment = new NodeEnvironment(settings, environment); - mapperRegistry = new IndicesModule().getMapperRegistry(); + mapperRegistry = new IndicesModule(new NamedWriteableRegistry()).getMapperRegistry(); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 51df3ee0386..7dd60de6c40 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -58,6 +58,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.uid.Versions; @@ -2015,7 +2016,7 @@ public class InternalEngineTests extends ESTestCase { IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings); AnalysisService analysisService = new AnalysisService(indexSettings, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap()); - MapperRegistry mapperRegistry = new IndicesModule().getMapperRegistry(); + MapperRegistry mapperRegistry = new IndicesModule(new NamedWriteableRegistry()).getMapperRegistry(); MapperService mapperService = new MapperService(indexSettings, analysisService, similarityService, mapperRegistry, () -> null); DocumentMapper.Builder b = new DocumentMapper.Builder(rootBuilder, mapperService); this.docMapper = b.build(mapperService); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/internal/FieldNamesFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/internal/FieldNamesFieldMapperTests.java index cd7f46844fc..2ec5aee9d15 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/internal/FieldNamesFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/internal/FieldNamesFieldMapperTests.java @@ -24,6 +24,7 @@ import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.compress.CompressedXContent; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.IndexService; @@ -234,7 +235,7 @@ public class FieldNamesFieldMapperTests extends ESSingleNodeTestCase { public void testSeesFieldsFromPlugins() throws IOException { IndexService indexService = createIndex("test"); - IndicesModule indicesModule = new IndicesModule(); + IndicesModule indicesModule = new IndicesModule(new NamedWriteableRegistry()); indicesModule.registerMetadataMapper("_dummy", new DummyMetadataFieldMapper.TypeParser()); final MapperRegistry mapperRegistry = indicesModule.getMapperRegistry(); MapperService mapperService = new MapperService(indexService.getIndexSettings(), indexService.analysisService(), indexService.similarityService(), mapperRegistry, indexService::newQueryShardContext); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java index 8801b3da45e..09c16e4ae46 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java @@ -151,7 +151,7 @@ public class AggregatorParsingTests extends ESTestCase { }; scriptModule.prepareSettings(settingsModule); injector = new ModulesBuilder().add(new EnvironmentModule(new Environment(settings)), settingsModule, - new ThreadPoolModule(threadPool), scriptModule, new IndicesModule() { + new ThreadPoolModule(threadPool), scriptModule, new IndicesModule(namedWriteableRegistry) { @Override protected void configure() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index c81ee0bb9c2..d43c54a0e09 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -169,7 +169,7 @@ public abstract class BaseAggregationTestCase contextFactory.get()); IndicesFieldDataCache cache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {}); diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/AttachmentUnitTestCase.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/AttachmentUnitTestCase.java index 2d55587961b..e0d5d7a2ec6 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/AttachmentUnitTestCase.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/AttachmentUnitTestCase.java @@ -21,6 +21,7 @@ package org.elasticsearch.mapper.attachments; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.indices.IndicesModule; @@ -32,7 +33,7 @@ public abstract class AttachmentUnitTestCase extends ESTestCase { protected Settings testSettings; protected static IndicesModule getIndicesModuleWithRegisteredAttachmentMapper() { - IndicesModule indicesModule = new IndicesModule(); + IndicesModule indicesModule = new IndicesModule(new NamedWriteableRegistry()); indicesModule.registerMapper(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); return indicesModule; } diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java index 352d84e975a..ce44fef59a5 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper.size; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressedXContent; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; @@ -47,7 +48,7 @@ public class SizeMappingTests extends ESSingleNodeTestCase { @Before public void before() { indexService = createIndex("test"); - IndicesModule indices = new IndicesModule(); + IndicesModule indices = new IndicesModule(new NamedWriteableRegistry()); indices.registerMetadataMapper(SizeFieldMapper.NAME, new SizeFieldMapper.TypeParser()); mapperService = new MapperService(indexService.getIndexSettings(), indexService.analysisService(), indexService.similarityService(), indices.getMapperRegistry(), indexService::newQueryShardContext); parser = mapperService.documentMapperParser(); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json index 494ff408273..f7b1fdc010a 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json @@ -3,18 +3,13 @@ "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html", "methods": ["PUT", "POST"], "url": { - "path": "/{alias}/_rollover/{target_alias}", - "paths": ["/{alias}/_rollover/{target_alias}"], + "path": "/{alias}/_rollover", + "paths": ["/{alias}/_rollover", "/{alias}/_rollover/{target_alias}"], "parts": { "alias": { "type" : "string", "required" : true, "description" : "The name of the alias to rollover" - }, - "target_alias": { - "type" : "string", - "required" : false, - "description" : "The name of optional target alias" } }, "params": { diff --git a/test/framework/src/main/java/org/elasticsearch/index/MapperTestUtils.java b/test/framework/src/main/java/org/elasticsearch/index/MapperTestUtils.java index b2b172e88ba..fe434246035 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/MapperTestUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/index/MapperTestUtils.java @@ -21,6 +21,7 @@ package org.elasticsearch.index; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.analysis.AnalysisRegistry; @@ -39,7 +40,7 @@ import java.util.Collections; public class MapperTestUtils { public static MapperService newMapperService(Path tempDir, Settings indexSettings) throws IOException { - IndicesModule indicesModule = new IndicesModule(); + IndicesModule indicesModule = new IndicesModule(new NamedWriteableRegistry()); return newMapperService(tempDir, indexSettings, indicesModule); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index c27617a7287..db086cf16e1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -934,7 +934,7 @@ public abstract class AbstractQueryTestCase> new EnvironmentModule(new Environment(settings)), settingsModule, new ThreadPoolModule(threadPool), - new IndicesModule() { + new IndicesModule(namedWriteableRegistry) { @Override public void configure() { // skip services From 1e329099f99d86dea0e3aaa08374cf8b9345f701 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Mon, 6 Jun 2016 18:50:45 -0400 Subject: [PATCH 10/87] enhance rollover request --- .../admin/indices/rollover/Condition.java | 14 ++++ .../indices/rollover/RolloverRequest.java | 12 +++ .../rollover/RolloverRequestBuilder.java | 5 ++ .../indices/rollover/RolloverResponse.java | 79 ++++++++++++++++++- .../rollover/TransportRolloverAction.java | 56 ++++++++----- .../indices/RestRolloverIndexAction.java | 21 +---- .../indices/rollover/ConditionTests.java | 41 ++++++++++ .../admin/indices/rollover/RolloverIT.java | 38 +++++++++ .../TransportRolloverActionTests.java | 73 ++++------------- 9 files changed, 244 insertions(+), 95 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/action/admin/indices/rollover/ConditionTests.java diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java index bd70dda62fc..fee08433e9c 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java @@ -44,10 +44,12 @@ public abstract class Condition implements NamedWriteable { public final static String NAME = "max_age"; public MaxAge(TimeValue value) { + super(NAME); this.value = value; } public MaxAge(StreamInput in) throws IOException { + super(NAME); this.value = TimeValue.timeValueMillis(in.readLong()); } @@ -71,10 +73,12 @@ public abstract class Condition implements NamedWriteable { public final static String NAME = "max_docs"; public MaxDocs(Long value) { + super(NAME); this.value = value; } public MaxDocs(StreamInput in) throws IOException { + super(NAME); this.value = in.readLong(); } @@ -95,6 +99,16 @@ public abstract class Condition implements NamedWriteable { } protected T value; + protected final String name; + + protected Condition(String name) { + this.name = name; + } public abstract boolean matches(T value); + + @Override + public final String toString() { + return "[" + name + ": " + value + "]"; + } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index 03c288f53dd..0d55d256390 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -48,6 +48,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; public class RolloverRequest extends AcknowledgedRequest implements IndicesRequest { private String sourceAlias; + private boolean simulate; private Set conditions = new HashSet<>(2); public static ObjectParser, ParseFieldMatcherSupplier> TLP_PARSER = @@ -77,6 +78,7 @@ public class RolloverRequest extends AcknowledgedRequest implem public void readFrom(StreamInput in) throws IOException { super.readFrom(in); sourceAlias = in.readString(); + simulate = in.readBoolean(); int size = in.readVInt(); for (int i = 0; i < size; i++) { this.conditions.add(in.readNamedWriteable(Condition.class)); @@ -87,6 +89,7 @@ public class RolloverRequest extends AcknowledgedRequest implem public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(sourceAlias); + out.writeBoolean(simulate); out.writeVInt(conditions.size()); for (Condition condition : conditions) { out.writeNamedWriteable(condition); @@ -107,6 +110,10 @@ public class RolloverRequest extends AcknowledgedRequest implem this.sourceAlias = sourceAlias; } + public void simulate(boolean simulate) { + this.simulate = simulate; + } + public void addMaxIndexAgeCondition(TimeValue age) { this.conditions.add(new Condition.MaxAge(age)); } @@ -115,6 +122,10 @@ public class RolloverRequest extends AcknowledgedRequest implem this.conditions.add(new Condition.MaxDocs(docs)); } + public boolean isSimulate() { + return simulate; + } + public Set getConditions() { return conditions; } @@ -135,4 +146,5 @@ public class RolloverRequest extends AcknowledgedRequest implem throw new ElasticsearchParseException("failed to parse content type for rollover index source"); } } + } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java index 2a95468de69..ea495bc6eba 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -46,4 +46,9 @@ public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder> conditionStatus; + private boolean simulate; + private boolean rolledOver; + private boolean rolloverIndexCreated; RolloverResponse() { } - RolloverResponse(String oldIndex, String newIndex) { + RolloverResponse(String oldIndex, String newIndex, Set> conditionStatus, + boolean simulate, boolean rolledOver, boolean rolloverIndexCreated) { this.oldIndex = oldIndex; this.newIndex = newIndex; + this.simulate = simulate; + this.rolledOver = rolledOver; + this.rolloverIndexCreated = rolloverIndexCreated; + this.conditionStatus = conditionStatus; } public String getOldIndex() { @@ -46,11 +62,38 @@ public final class RolloverResponse extends ActionResponse { return newIndex; } + public Set> getConditionStatus() { + return conditionStatus; + } + + public boolean isSimulate() { + return simulate; + } + + public boolean isRolledOver() { + return rolledOver; + } + + public boolean isRolloverIndexCreated() { + return rolloverIndexCreated; + } + @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); oldIndex = in.readString(); newIndex = in.readString(); + int conditionSize = in.readVInt(); + Set> conditions = new HashSet<>(conditionSize); + for (int i = 0; i < conditionSize; i++) { + String condition = in.readString(); + boolean satisfied = in.readBoolean(); + conditions.add(new AbstractMap.SimpleEntry<>(condition, satisfied)); + } + conditionStatus = conditions; + simulate = in.readBoolean(); + rolledOver = in.readBoolean(); + rolloverIndexCreated = in.readBoolean(); } @Override @@ -58,5 +101,37 @@ public final class RolloverResponse extends ActionResponse { super.writeTo(out); out.writeString(oldIndex); out.writeString(newIndex); + out.writeVInt(conditionStatus.size()); + for (Map.Entry entry : conditionStatus) { + out.writeString(entry.getKey()); + out.writeBoolean(entry.getValue()); + } + out.writeBoolean(simulate); + out.writeBoolean(rolledOver); + out.writeBoolean(rolloverIndexCreated); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.field(Fields.OLD_INDEX, oldIndex); + builder.field(Fields.NEW_INDEX, newIndex); + builder.field(Fields.ROLLED_OVER, rolledOver); + builder.field(Fields.SIMULATED, simulate); + builder.field(Fields.ROLLOVER_INDEX_CREATED, rolloverIndexCreated); + builder.startObject(Fields.CONDITIONS); + for (Map.Entry entry : conditionStatus) { + builder.field(entry.getKey(), entry.getValue()); + } + builder.endObject(); + return builder; + } + + static final class Fields { + static final String NEW_INDEX = "new_index"; + static final String OLD_INDEX = "old_index"; + static final String SIMULATED = "simulated"; + static final String ROLLED_OVER = "rolled_over"; + static final String ROLLOVER_INDEX_CREATED = "rollover_index_created"; + static final String CONDITIONS = "conditions"; } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index fa8782aca03..05bc674b8d3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -47,7 +47,11 @@ import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import java.util.AbstractMap; +import java.util.HashSet; +import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * Main class to swap the index pointed to by an alias, given some predicates @@ -105,9 +109,23 @@ public class TransportRolloverAction extends TransportMasterNodeAction> evaluatedConditions = + evaluateConditions(rolloverRequest.getConditions(), docCount, indexAge); + final Set> conditionStatus = evaluatedConditions.stream() + .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey().toString(), entry.getValue())) + .collect(Collectors.toSet()); + final String rolloverIndexName = generateRolloverIndexName(sourceIndexName); + final boolean createRolloverIndex = metaData.index(rolloverIndexName) == null; + if (rolloverRequest.isSimulate()) { + listener.onResponse( + new RolloverResponse(sourceIndexName, rolloverIndexName, conditionStatus, true, false, + false)); + return; + } + if (conditionStatus.stream().allMatch(Map.Entry::getValue)) { + final RolloverResponse rolloverResponse = + new RolloverResponse(sourceIndexName, rolloverIndexName, conditionStatus, false, true, + createRolloverIndex); if (createRolloverIndex) { CreateIndexClusterStateUpdateRequest updateRequest = prepareCreateIndexRequest(rolloverIndexName, rolloverRequest); @@ -116,7 +134,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction { private final ActionListener listener; - private final String oldIndex; - private final String newIndex; + private final RolloverResponse response; - public IndicesAliasesListener(String oldIndex, String newIndex, ActionListener listener) { - this.oldIndex = oldIndex; - this.newIndex = newIndex; + public IndicesAliasesListener(RolloverResponse response, ActionListener listener) { + this.response = response; this.listener = listener; } @Override public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { - listener.onResponse(new RolloverResponse(oldIndex, newIndex)); + listener.onResponse(response); } @Override @@ -199,24 +218,21 @@ public class TransportRolloverAction extends TransportMasterNodeAction conditions, long docCount, long indexAge) { + static Set> evaluateConditions(Set conditions, long docCount, long indexAge) { + Set> result = new HashSet<>(conditions.size()); for (Condition condition: conditions) { if (condition instanceof Condition.MaxAge) { Condition.MaxAge maxAge = (Condition.MaxAge) condition; final TimeValue age = TimeValue.timeValueMillis(indexAge); - if (maxAge.matches(age) == false) { - return false; - } + result.add(new AbstractMap.SimpleEntry<>(condition, maxAge.matches(age))); } else if (condition instanceof Condition.MaxDocs) { final Condition.MaxDocs maxDocs = (Condition.MaxDocs) condition; - if (maxDocs.matches(docCount) == false) { - return false; - } + result.add(new AbstractMap.SimpleEntry<>(condition, maxDocs.matches(docCount))); } else { throw new IllegalArgumentException("unknown condition [" + condition.getClass().getSimpleName() + "]"); } } - return true; + return result; } static void validate(MetaData metaData, RolloverRequest request) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index 50ec45e9229..b56b04166fb 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -20,20 +20,14 @@ package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; -import org.elasticsearch.action.admin.indices.rollover.RolloverResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.action.support.RestBuilderListener; - -import static org.elasticsearch.rest.RestStatus.OK; +import org.elasticsearch.rest.action.support.RestToXContentListener; /** * @@ -45,6 +39,7 @@ public class RestRolloverIndexAction extends BaseRestHandler { super(settings, client); controller.registerHandler(RestRequest.Method.PUT, "/{alias}/_rollover", this); controller.registerHandler(RestRequest.Method.POST, "/{alias}/_rollover", this); + controller.registerHandler(RestRequest.Method.GET, "/{alias}/_rollover", this); } @Override @@ -56,17 +51,9 @@ public class RestRolloverIndexAction extends BaseRestHandler { if (request.hasContent()) { rolloverIndexRequest.source(request.content()); } + rolloverIndexRequest.simulate(request.method() == RestRequest.Method.GET || request.paramAsBoolean("simulate", false)); rolloverIndexRequest.timeout(request.paramAsTime("timeout", rolloverIndexRequest.timeout())); rolloverIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", rolloverIndexRequest.masterNodeTimeout())); - client.admin().indices().rolloverIndex(rolloverIndexRequest, new RestBuilderListener(channel) { - @Override - public RestResponse buildResponse(RolloverResponse rolloverResponse, XContentBuilder builder) throws Exception { - builder.startObject(); - builder.field("old_index", rolloverResponse.getOldIndex()); - builder.field("new_index", rolloverResponse.getNewIndex()); - builder.endObject(); - return new BytesRestResponse(OK, builder); - } - }); + client.admin().indices().rolloverIndex(rolloverIndexRequest, new RestToXContentListener<>(channel)); } } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/ConditionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/ConditionTests.java new file mode 100644 index 00000000000..3ce1b84d82c --- /dev/null +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/ConditionTests.java @@ -0,0 +1,41 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.test.ESTestCase; + +import static org.hamcrest.Matchers.equalTo; + +public class ConditionTests extends ESTestCase { + + public void testMaxAge() throws Exception { + final Condition.MaxAge maxAge = new Condition.MaxAge(TimeValue.timeValueMillis(10)); + assertThat(maxAge.matches(TimeValue.timeValueMillis(randomIntBetween(0, 9))), equalTo(false)); + assertThat(maxAge.matches(TimeValue.timeValueMillis(randomIntBetween(10, 100))), equalTo(true)); + } + + public void testMaxDocs() throws Exception { + final Condition.MaxDocs maxDocs = new Condition.MaxDocs(10L); + assertThat(maxDocs.matches((long) randomIntBetween(0, 9)), equalTo(false)); + assertThat(maxDocs.matches((long) randomIntBetween(10, 100)), equalTo(true)); + + } +} diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java index 3ab9c8cc040..9c0f3b7b96a 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java @@ -25,6 +25,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESIntegTestCase; +import java.util.Map; + import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @@ -36,6 +38,10 @@ public class RolloverIT extends ESIntegTestCase { final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); assertThat(response.getOldIndex(), equalTo("test_index")); assertThat(response.getNewIndex(), equalTo("test_index-1")); + assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isRolledOver(), equalTo(true)); + assertThat(response.isRolloverIndexCreated(), equalTo(true)); + assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index"); assertFalse(oldIndex.getAliases().containsKey("test_alias")); @@ -50,6 +56,10 @@ public class RolloverIT extends ESIntegTestCase { final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); assertThat(response.getOldIndex(), equalTo("test_index")); assertThat(response.getNewIndex(), equalTo("test_index-1")); + assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isRolledOver(), equalTo(true)); + assertThat(response.isRolloverIndexCreated(), equalTo(true)); + assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index"); assertFalse(oldIndex.getAliases().containsKey("test_alias")); @@ -57,6 +67,24 @@ public class RolloverIT extends ESIntegTestCase { assertTrue(newIndex.getAliases().containsKey("test_alias")); } + public void testRolloverSimulate() throws Exception { + assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); + index("test_index", "type1", "1", "field", "value"); + flush("test_index"); + final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").simulate(true).get(); + assertThat(response.getOldIndex(), equalTo("test_index")); + assertThat(response.getNewIndex(), equalTo("test_index-1")); + assertThat(response.isSimulate(), equalTo(true)); + assertThat(response.isRolledOver(), equalTo(false)); + assertThat(response.isRolloverIndexCreated(), equalTo(false)); + assertThat(response.getConditionStatus().size(), equalTo(0)); + final ClusterState state = client().admin().cluster().prepareState().get().getState(); + final IndexMetaData oldIndex = state.metaData().index("test_index"); + assertTrue(oldIndex.getAliases().containsKey("test_alias")); + final IndexMetaData newIndex = state.metaData().index("test_index-1"); + assertNull(newIndex); + } + public void testRolloverConditionsNotMet() throws Exception { assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); index("test_index", "type1", "1", "field", "value"); @@ -65,6 +93,13 @@ public class RolloverIT extends ESIntegTestCase { .addMaxIndexAgeCondition(TimeValue.timeValueHours(4)).get(); assertThat(response.getOldIndex(), equalTo("test_index")); assertThat(response.getNewIndex(), equalTo("test_index")); + assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isRolledOver(), equalTo(false)); + assertThat(response.isRolloverIndexCreated(), equalTo(false)); + assertThat(response.getConditionStatus().size(), equalTo(1)); + final Map.Entry conditionEntry = response.getConditionStatus().iterator().next(); + assertThat(conditionEntry.getKey(), equalTo(new Condition.MaxAge(TimeValue.timeValueHours(4)).toString())); + assertThat(conditionEntry.getValue(), equalTo(false)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index"); assertTrue(oldIndex.getAliases().containsKey("test_alias")); @@ -81,6 +116,9 @@ public class RolloverIT extends ESIntegTestCase { final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); assertThat(response.getOldIndex(), equalTo("test_index")); assertThat(response.getNewIndex(), equalTo("test_index-1")); + assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isRolledOver(), equalTo(true)); + assertThat(response.isRolloverIndexCreated(), equalTo(false)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index"); assertFalse(oldIndex.getAliases().containsKey("test_alias")); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java index ff121ff3dfb..636378a5872 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java @@ -27,44 +27,13 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.test.ESTestCase; -import java.util.Collections; -import java.util.Set; - import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; public class TransportRolloverActionTests extends ESTestCase { - public void testSatisfyConditions() throws Exception { - Set conditions = Collections.emptySet(); - assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), - randomLong())); - - conditions = Collections.singleton(new Condition.MaxAge(TimeValue.timeValueMillis(10))); - assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), - TimeValue.timeValueMillis(randomIntBetween(10, 100)).getMillis())); - assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomLong(), - TimeValue.timeValueMillis(randomIntBetween(0, 9)).getMillis())); - - conditions = Collections.singleton(new Condition.MaxDocs(10L)); - assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(10, 100), - randomLong())); - assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1, 9), - randomLong())); - - conditions = Sets.newHashSet(new Condition.MaxAge(TimeValue.timeValueMillis(100)), new Condition.MaxDocs(1000L)); - assertTrue(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1000, 1500), - TimeValue.timeValueMillis(randomIntBetween(100, 1000)).getMillis())); - assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1, 999), - TimeValue.timeValueMillis(randomIntBetween(100, 1000)).getMillis())); - assertFalse(TransportRolloverAction.satisfiesConditions(conditions, randomIntBetween(1000, 1500), - TimeValue.timeValueMillis(randomIntBetween(0, 99)).getMillis())); - } - public void testCreateUpdateAliasRequest() throws Exception { String sourceAlias = randomAsciiOfLength(10); String sourceIndex = randomAsciiOfLength(10); @@ -114,35 +83,27 @@ public class TransportRolloverActionTests extends ESTestCase { .putAlias(AliasMetaData.builder(aliasWithMultipleIndices)) ).build(); - try { - TransportRolloverAction.validate(metaData, new RolloverRequest(aliasWithMultipleIndices)); - fail("expected to throw exception"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("source alias maps to multiple indices")); - } - - try { - TransportRolloverAction.validate(metaData, new RolloverRequest(randomFrom(index1, index2))); - fail("expected to throw exception"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("source alias is a concrete index")); - } - - try { - TransportRolloverAction.validate(metaData, new RolloverRequest(randomAsciiOfLength(5))); - fail("expected to throw exception"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), equalTo("source alias does not exist")); - } - + expectThrows(IllegalArgumentException.class, () -> + TransportRolloverAction.validate(metaData, new RolloverRequest(aliasWithMultipleIndices))); + expectThrows(IllegalArgumentException.class, () -> + TransportRolloverAction.validate(metaData, new RolloverRequest(randomFrom(index1, index2)))); + expectThrows(IllegalArgumentException.class, () -> + TransportRolloverAction.validate(metaData, new RolloverRequest(randomAsciiOfLength(5))) + ); TransportRolloverAction.validate(metaData, new RolloverRequest(alias)); } public void testGenerateRolloverIndexName() throws Exception { - String index = randomAsciiOfLength(10); - assertThat(TransportRolloverAction.generateRolloverIndexName(index), not(equalTo(index))); - assertThat(TransportRolloverAction.generateRolloverIndexName("index"), equalTo("index-1")); - assertThat(TransportRolloverAction.generateRolloverIndexName("index-1"), equalTo("index-2")); + String indexNotEndingInNumbers = randomAsciiOfLength(10) + "A"; + assertThat(TransportRolloverAction.generateRolloverIndexName(indexNotEndingInNumbers), + not(equalTo(indexNotEndingInNumbers))); + assertThat(TransportRolloverAction.generateRolloverIndexName(indexNotEndingInNumbers), + equalTo(indexNotEndingInNumbers + "-1")); + int num = randomIntBetween(0, 100); + final String indexPrefix = randomAsciiOfLength(10); + String indexEndingInNumbers = indexPrefix + "-" + num; + assertThat(TransportRolloverAction.generateRolloverIndexName(indexEndingInNumbers), + equalTo(indexPrefix + "-" + (num + 1))); assertThat(TransportRolloverAction.generateRolloverIndexName("index-name-1"), equalTo("index-name-2")); assertThat(TransportRolloverAction.generateRolloverIndexName("index-name"), equalTo("index-name-1")); } From d8d60d294ea89a4e94749a86b394257bb431ee84 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Mon, 6 Jun 2016 18:54:20 -0400 Subject: [PATCH 11/87] remove put method --- .../rest/action/admin/indices/RestRolloverIndexAction.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index b56b04166fb..963080c3122 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -37,7 +37,6 @@ public class RestRolloverIndexAction extends BaseRestHandler { @Inject public RestRolloverIndexAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(RestRequest.Method.PUT, "/{alias}/_rollover", this); controller.registerHandler(RestRequest.Method.POST, "/{alias}/_rollover", this); controller.registerHandler(RestRequest.Method.GET, "/{alias}/_rollover", this); } From 76c59b7417bc197fda3ef1e8a2e1a0d8a3b387ad Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Tue, 7 Jun 2016 22:37:10 -0400 Subject: [PATCH 12/87] remove unused request param --- .../src/main/resources/rest-api-spec/api/indices.rollover.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json index f7b1fdc010a..22ae6498149 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json @@ -4,7 +4,7 @@ "methods": ["PUT", "POST"], "url": { "path": "/{alias}/_rollover", - "paths": ["/{alias}/_rollover", "/{alias}/_rollover/{target_alias}"], + "paths": ["/{alias}/_rollover"], "parts": { "alias": { "type" : "string", From 134a4e5e528baa8bc66c6bdf3497ccd49839ce99 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Tue, 7 Jun 2016 22:38:47 -0400 Subject: [PATCH 13/87] incorporate feedback --- .../admin/indices/rollover/Condition.java | 87 +++++-------------- .../indices/rollover/MaxAgeCondition.java | 56 ++++++++++++ .../indices/rollover/MaxDocsCondition.java | 54 ++++++++++++ .../indices/rollover/RolloverRequest.java | 4 +- .../indices/rollover/RolloverResponse.java | 6 +- .../rollover/TransportRolloverAction.java | 79 ++++++----------- .../elasticsearch/indices/IndicesModule.java | 6 +- .../indices/rollover/ConditionTests.java | 27 ++++-- .../admin/indices/rollover/RolloverIT.java | 2 +- .../TransportRolloverActionTests.java | 66 ++++++++++++-- 10 files changed, 252 insertions(+), 135 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxAgeCondition.java create mode 100644 core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxDocsCondition.java diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java index fee08433e9c..12c3ef45993 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java @@ -22,12 +22,9 @@ package org.elasticsearch.action.admin.indices.rollover; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.NamedWriteable; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ObjectParser; -import java.io.IOException; import java.util.Set; public abstract class Condition implements NamedWriteable { @@ -35,67 +32,9 @@ public abstract class Condition implements NamedWriteable { new ObjectParser<>("conditions", null); static { PARSER.declareString((conditions, s) -> - conditions.add(new MaxAge(TimeValue.parseTimeValue(s, MaxAge.NAME))), new ParseField(MaxAge.NAME)); + conditions.add(new MaxAgeCondition(TimeValue.parseTimeValue(s, MaxAgeCondition.NAME))), new ParseField(MaxAgeCondition.NAME)); PARSER.declareLong((conditions, value) -> - conditions.add(new MaxDocs(value)), new ParseField(MaxDocs.NAME)); - } - - public static class MaxAge extends Condition { - public final static String NAME = "max_age"; - - public MaxAge(TimeValue value) { - super(NAME); - this.value = value; - } - - public MaxAge(StreamInput in) throws IOException { - super(NAME); - this.value = TimeValue.timeValueMillis(in.readLong()); - } - - @Override - public boolean matches(TimeValue value) { - return this.value.getMillis() <= value.getMillis(); - } - - @Override - public String getWriteableName() { - return NAME; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeLong(value.getMillis()); - } - } - - public static class MaxDocs extends Condition { - public final static String NAME = "max_docs"; - - public MaxDocs(Long value) { - super(NAME); - this.value = value; - } - - public MaxDocs(StreamInput in) throws IOException { - super(NAME); - this.value = in.readLong(); - } - - @Override - public boolean matches(Long value) { - return this.value <= value; - } - - @Override - public String getWriteableName() { - return NAME; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeLong(value); - } + conditions.add(new MaxDocsCondition(value)), new ParseField(MaxDocsCondition.NAME)); } protected T value; @@ -105,10 +44,30 @@ public abstract class Condition implements NamedWriteable { this.name = name; } - public abstract boolean matches(T value); + public abstract Result evaluate(final Stats stats); @Override public final String toString() { return "[" + name + ": " + value + "]"; } + + public static class Stats { + public final long numDocs; + public final long indexCreated; + + public Stats(long numDocs, long indexCreated) { + this.numDocs = numDocs; + this.indexCreated = indexCreated; + } + } + + public static class Result { + public final Condition condition; + public final boolean matched; + + protected Result(Condition condition, boolean matched) { + this.condition = condition; + this.matched = matched; + } + } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxAgeCondition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxAgeCondition.java new file mode 100644 index 00000000000..0a7e85bb129 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxAgeCondition.java @@ -0,0 +1,56 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.unit.TimeValue; + +import java.io.IOException; + +public class MaxAgeCondition extends Condition { + public final static String NAME = "max_age"; + + public MaxAgeCondition(TimeValue value) { + super(NAME); + this.value = value; + } + + public MaxAgeCondition(StreamInput in) throws IOException { + super(NAME); + this.value = TimeValue.timeValueMillis(in.readLong()); + } + + @Override + public Result evaluate(final Stats stats) { + long indexAge = System.currentTimeMillis() - stats.indexCreated; + return new Result(this, this.value.getMillis() <= indexAge); + } + + @Override + public String getWriteableName() { + return NAME; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeLong(value.getMillis()); + } +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxDocsCondition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxDocsCondition.java new file mode 100644 index 00000000000..e1c599c23d4 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxDocsCondition.java @@ -0,0 +1,54 @@ +/* + * 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.indices.rollover; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + +public class MaxDocsCondition extends Condition { + public final static String NAME = "max_docs"; + + public MaxDocsCondition(Long value) { + super(NAME); + this.value = value; + } + + public MaxDocsCondition(StreamInput in) throws IOException { + super(NAME); + this.value = in.readLong(); + } + + @Override + public Result evaluate(final Stats stats) { + return new Result(this, this.value <= stats.numDocs); + } + + @Override + public String getWriteableName() { + return NAME; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeLong(value); + } +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index 0d55d256390..dd1facdb6e2 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -115,11 +115,11 @@ public class RolloverRequest extends AcknowledgedRequest implem } public void addMaxIndexAgeCondition(TimeValue age) { - this.conditions.add(new Condition.MaxAge(age)); + this.conditions.add(new MaxAgeCondition(age)); } public void addMaxIndexDocsCondition(long docs) { - this.conditions.add(new Condition.MaxDocs(docs)); + this.conditions.add(new MaxDocsCondition(docs)); } public boolean isSimulate() { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java index a2abe044930..fbca8af99cc 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java @@ -44,14 +44,16 @@ public final class RolloverResponse extends ActionResponse implements ToXContent RolloverResponse() { } - RolloverResponse(String oldIndex, String newIndex, Set> conditionStatus, + RolloverResponse(String oldIndex, String newIndex, Set conditionResults, boolean simulate, boolean rolledOver, boolean rolloverIndexCreated) { this.oldIndex = oldIndex; this.newIndex = newIndex; this.simulate = simulate; this.rolledOver = rolledOver; this.rolloverIndexCreated = rolloverIndexCreated; - this.conditionStatus = conditionStatus; + this.conditionStatus = conditionResults.stream() + .map(result -> new AbstractMap.SimpleEntry<>(result.condition.toString(), result.matched)) + .collect(Collectors.toSet()); } public String getOldIndex() { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index 05bc674b8d3..3eed74661a8 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -41,16 +41,12 @@ import org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.shard.DocsStats; -import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import java.util.AbstractMap; -import java.util.HashSet; -import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -104,27 +100,20 @@ public class TransportRolloverAction extends TransportMasterNodeAction() { @Override - public void onResponse(IndicesStatsResponse indicesStatsResponse) { - final IndexMetaData sourceIndex = metaData.index(sourceIndexName); - DocsStats docsStats = indicesStatsResponse.getTotal().getDocs(); - long docCount = docsStats == null ? 0 : docsStats.getCount(); - long indexAge = System.currentTimeMillis() - sourceIndex.getCreationDate(); - final Set> evaluatedConditions = - evaluateConditions(rolloverRequest.getConditions(), docCount, indexAge); - final Set> conditionStatus = evaluatedConditions.stream() - .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey().toString(), entry.getValue())) - .collect(Collectors.toSet()); + public void onResponse(IndicesStatsResponse statsResponse) { + final Set conditionResults = evaluateConditions(rolloverRequest.getConditions(), + statsResponse.getTotal().getDocs(), metaData.index(sourceIndexName)); final String rolloverIndexName = generateRolloverIndexName(sourceIndexName); - final boolean createRolloverIndex = metaData.index(rolloverIndexName) == null; if (rolloverRequest.isSimulate()) { listener.onResponse( - new RolloverResponse(sourceIndexName, rolloverIndexName, conditionStatus, true, false, + new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, true, false, false)); return; } - if (conditionStatus.stream().allMatch(Map.Entry::getValue)) { + if (conditionResults.stream().anyMatch(result -> result.matched)) { + boolean createRolloverIndex = metaData.index(rolloverIndexName) == null; final RolloverResponse rolloverResponse = - new RolloverResponse(sourceIndexName, rolloverIndexName, conditionStatus, false, true, + new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, false, true, createRolloverIndex); if (createRolloverIndex) { CreateIndexClusterStateUpdateRequest updateRequest = @@ -139,11 +128,6 @@ public class TransportRolloverAction extends TransportMasterNodeAction { private final ActionListener listener; @@ -203,36 +188,26 @@ public class TransportRolloverAction extends TransportMasterNodeAction> evaluateConditions(Set conditions, long docCount, long indexAge) { - Set> result = new HashSet<>(conditions.size()); - for (Condition condition: conditions) { - if (condition instanceof Condition.MaxAge) { - Condition.MaxAge maxAge = (Condition.MaxAge) condition; - final TimeValue age = TimeValue.timeValueMillis(indexAge); - result.add(new AbstractMap.SimpleEntry<>(condition, maxAge.matches(age))); - } else if (condition instanceof Condition.MaxDocs) { - final Condition.MaxDocs maxDocs = (Condition.MaxDocs) condition; - result.add(new AbstractMap.SimpleEntry<>(condition, maxDocs.matches(docCount))); - } else { - throw new IllegalArgumentException("unknown condition [" + condition.getClass().getSimpleName() + "]"); - } - } - return result; + static Set evaluateConditions(final Set conditions, + final DocsStats docsStats, final IndexMetaData metaData) { + final long numDocs = docsStats == null ? 0 : docsStats.getCount(); + final Condition.Stats stats = new Condition.Stats(numDocs, metaData.getCreationDate()); + return conditions.stream() + .map(condition -> condition.evaluate(stats)) + .collect(Collectors.toSet()); } static void validate(MetaData metaData, RolloverRequest request) { diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesModule.java b/core/src/main/java/org/elasticsearch/indices/IndicesModule.java index 885e2d78eca..1817a71073c 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesModule.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesModule.java @@ -20,6 +20,8 @@ package org.elasticsearch.indices; import org.elasticsearch.action.admin.indices.rollover.Condition; +import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition; +import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition; import org.elasticsearch.action.update.UpdateHelper; import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService; import org.elasticsearch.common.geo.ShapesAvailability; @@ -86,8 +88,8 @@ public class IndicesModule extends AbstractModule { } private void registerBuildInWritables() { - namedWritableRegistry.register(Condition.class, Condition.MaxAge.NAME, Condition.MaxAge::new); - namedWritableRegistry.register(Condition.class, Condition.MaxDocs.NAME, Condition.MaxDocs::new); + namedWritableRegistry.register(Condition.class, MaxAgeCondition.NAME, MaxAgeCondition::new); + namedWritableRegistry.register(Condition.class, MaxDocsCondition.NAME, MaxDocsCondition::new); } private void registerBuiltInMappers() { diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/ConditionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/ConditionTests.java index 3ce1b84d82c..95f186ba0e5 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/ConditionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/ConditionTests.java @@ -27,15 +27,30 @@ import static org.hamcrest.Matchers.equalTo; public class ConditionTests extends ESTestCase { public void testMaxAge() throws Exception { - final Condition.MaxAge maxAge = new Condition.MaxAge(TimeValue.timeValueMillis(10)); - assertThat(maxAge.matches(TimeValue.timeValueMillis(randomIntBetween(0, 9))), equalTo(false)); - assertThat(maxAge.matches(TimeValue.timeValueMillis(randomIntBetween(10, 100))), equalTo(true)); + final MaxAgeCondition maxAgeCondition = new MaxAgeCondition(TimeValue.timeValueHours(1)); + + long indexCreatedMatch = System.currentTimeMillis() - TimeValue.timeValueMinutes(61).getMillis(); + Condition.Result evaluate = maxAgeCondition.evaluate(new Condition.Stats(0, indexCreatedMatch)); + assertThat(evaluate.condition, equalTo(maxAgeCondition)); + assertThat(evaluate.matched, equalTo(true)); + + long indexCreatedNotMatch = System.currentTimeMillis() - TimeValue.timeValueMinutes(59).getMillis(); + evaluate = maxAgeCondition.evaluate(new Condition.Stats(0, indexCreatedNotMatch)); + assertThat(evaluate.condition, equalTo(maxAgeCondition)); + assertThat(evaluate.matched, equalTo(false)); } public void testMaxDocs() throws Exception { - final Condition.MaxDocs maxDocs = new Condition.MaxDocs(10L); - assertThat(maxDocs.matches((long) randomIntBetween(0, 9)), equalTo(false)); - assertThat(maxDocs.matches((long) randomIntBetween(10, 100)), equalTo(true)); + final MaxDocsCondition maxDocsCondition = new MaxDocsCondition(100L); + long maxDocsMatch = randomIntBetween(100, 1000); + Condition.Result evaluate = maxDocsCondition.evaluate(new Condition.Stats(maxDocsMatch, 0)); + assertThat(evaluate.condition, equalTo(maxDocsCondition)); + assertThat(evaluate.matched, equalTo(true)); + + long maxDocsNotMatch = randomIntBetween(0, 99); + evaluate = maxDocsCondition.evaluate(new Condition.Stats(0, maxDocsNotMatch)); + assertThat(evaluate.condition, equalTo(maxDocsCondition)); + assertThat(evaluate.matched, equalTo(false)); } } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java index 9c0f3b7b96a..71d6f5a44f7 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java @@ -98,7 +98,7 @@ public class RolloverIT extends ESIntegTestCase { assertThat(response.isRolloverIndexCreated(), equalTo(false)); assertThat(response.getConditionStatus().size(), equalTo(1)); final Map.Entry conditionEntry = response.getConditionStatus().iterator().next(); - assertThat(conditionEntry.getKey(), equalTo(new Condition.MaxAge(TimeValue.timeValueHours(4)).toString())); + assertThat(conditionEntry.getKey(), equalTo(new MaxAgeCondition(TimeValue.timeValueHours(4)).toString())); assertThat(conditionEntry.getValue(), equalTo(false)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index"); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java index 636378a5872..12e1e90242e 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java @@ -27,13 +27,69 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.index.shard.DocsStats; import org.elasticsearch.test.ESTestCase; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.elasticsearch.action.admin.indices.rollover.TransportRolloverAction.evaluateConditions; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; public class TransportRolloverActionTests extends ESTestCase { + public void testEvaluateConditions() throws Exception { + MaxDocsCondition maxDocsCondition = new MaxDocsCondition(100L); + MaxAgeCondition maxAgeCondition = new MaxAgeCondition(TimeValue.timeValueHours(2)); + long matchMaxDocs = randomIntBetween(100, 1000); + long notMatchMaxDocs = randomIntBetween(0, 99); + final Settings settings = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .build(); + final IndexMetaData metaData = IndexMetaData.builder(randomAsciiOfLength(10)) + .creationDate(System.currentTimeMillis() - TimeValue.timeValueHours(3).getMillis()) + .settings(settings) + .build(); + final HashSet conditions = Sets.newHashSet(maxDocsCondition, maxAgeCondition); + Set results = evaluateConditions(conditions, new DocsStats(matchMaxDocs, 0L), metaData); + assertThat(results.size(), equalTo(2)); + for (Condition.Result result : results) { + assertThat(result.matched, equalTo(true)); + } + results = evaluateConditions(conditions, new DocsStats(notMatchMaxDocs, 0), metaData); + assertThat(results.size(), equalTo(2)); + for (Condition.Result result : results) { + if (result.condition instanceof MaxAgeCondition) { + assertThat(result.matched, equalTo(true)); + } else if (result.condition instanceof MaxDocsCondition) { + assertThat(result.matched, equalTo(false)); + } else { + fail("unknown condition result found " + result.condition); + } + } + results = evaluateConditions(conditions, null, metaData); + assertThat(results.size(), equalTo(2)); + for (Condition.Result result : results) { + if (result.condition instanceof MaxAgeCondition) { + assertThat(result.matched, equalTo(true)); + } else if (result.condition instanceof MaxDocsCondition) { + assertThat(result.matched, equalTo(false)); + } else { + fail("unknown condition result found " + result.condition); + } + } + } + + public void testCreateUpdateAliasRequest() throws Exception { String sourceAlias = randomAsciiOfLength(10); String sourceIndex = randomAsciiOfLength(10); @@ -94,17 +150,15 @@ public class TransportRolloverActionTests extends ESTestCase { } public void testGenerateRolloverIndexName() throws Exception { - String indexNotEndingInNumbers = randomAsciiOfLength(10) + "A"; - assertThat(TransportRolloverAction.generateRolloverIndexName(indexNotEndingInNumbers), - not(equalTo(indexNotEndingInNumbers))); - assertThat(TransportRolloverAction.generateRolloverIndexName(indexNotEndingInNumbers), - equalTo(indexNotEndingInNumbers + "-1")); + String invalidIndexName = randomAsciiOfLength(10) + "A"; + expectThrows(IllegalArgumentException.class, () -> + TransportRolloverAction.generateRolloverIndexName(invalidIndexName)); int num = randomIntBetween(0, 100); final String indexPrefix = randomAsciiOfLength(10); String indexEndingInNumbers = indexPrefix + "-" + num; assertThat(TransportRolloverAction.generateRolloverIndexName(indexEndingInNumbers), equalTo(indexPrefix + "-" + (num + 1))); assertThat(TransportRolloverAction.generateRolloverIndexName("index-name-1"), equalTo("index-name-2")); - assertThat(TransportRolloverAction.generateRolloverIndexName("index-name"), equalTo("index-name-1")); + assertThat(TransportRolloverAction.generateRolloverIndexName("index-name-2"), equalTo("index-name-3")); } } From dec0dcc30b94972502e6a3ee5bcd24cf35344df5 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Wed, 8 Jun 2016 11:25:35 -0400 Subject: [PATCH 14/87] minor cleanup --- .../rollover/TransportRolloverAction.java | 73 ++++++++----------- .../indices/RestRolloverIndexAction.java | 2 +- .../admin/indices/rollover/RolloverIT.java | 60 +++++++-------- .../TransportRolloverActionTests.java | 5 +- 4 files changed, 64 insertions(+), 76 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index 3eed74661a8..49ff6f1f23e 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -54,6 +54,7 @@ import java.util.stream.Collectors; */ public class TransportRolloverAction extends TransportMasterNodeAction { + private static final Pattern INDEX_NAME_PATTERN = Pattern.compile("^.*-(\\d)+$"); private final MetaDataCreateIndexService createIndexService; private final MetaDataIndexAliasesService indexAliasesService; private final Client client; @@ -110,7 +111,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction result.matched)) { + if (conditionResults.size() == 0 || conditionResults.stream().anyMatch(result -> result.matched)) { boolean createRolloverIndex = metaData.index(rolloverIndexName) == null; final RolloverResponse rolloverResponse = new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, false, true, @@ -118,23 +119,20 @@ public class TransportRolloverAction extends TransportMasterNodeAction() { - @Override - public void onResponse(ClusterStateUpdateResponse response) { - indexAliasesService.indicesAliases( - prepareIndicesAliasesRequest(sourceIndexName, rolloverIndexName, rolloverRequest), - new IndicesAliasesListener(rolloverResponse, listener)); - } + createIndexService.createIndex(updateRequest, + new ActionListener() { + @Override + public void onResponse(ClusterStateUpdateResponse response) { + rollover(rolloverRequest, rolloverResponse, listener); + } - @Override - public void onFailure(Throwable t) { - listener.onFailure(t); - } - }); + @Override + public void onFailure(Throwable t) { + listener.onFailure(t); + } + }); } else { - indexAliasesService.indicesAliases( - prepareIndicesAliasesRequest(sourceIndexName, rolloverIndexName, rolloverRequest), - new IndicesAliasesListener(rolloverResponse, listener)); + rollover(rolloverRequest, rolloverResponse, listener); } } else { // conditions not met @@ -153,42 +151,35 @@ public class TransportRolloverAction extends TransportMasterNodeAction listener) { + indexAliasesService.indicesAliases( + prepareRolloverAliasesUpdateRequest(response.getOldIndex(), response.getNewIndex(), request), + new ActionListener() { + @Override + public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { + listener.onResponse(response); + } - - private static final class IndicesAliasesListener implements ActionListener { - - private final ActionListener listener; - private final RolloverResponse response; - - public IndicesAliasesListener(RolloverResponse response, ActionListener listener) { - this.response = response; - this.listener = listener; - } - - @Override - public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { - listener.onResponse(response); - } - - @Override - public void onFailure(Throwable e) { - listener.onFailure(e); - } + @Override + public void onFailure(Throwable e) { + listener.onFailure(e); + } + }); } - static IndicesAliasesClusterStateUpdateRequest prepareIndicesAliasesRequest(String concreteSourceIndex, String targetIndex, - RolloverRequest request) { + static IndicesAliasesClusterStateUpdateRequest prepareRolloverAliasesUpdateRequest(String oldIndex, String newIndex, + RolloverRequest request) { final IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest() .ackTimeout(request.ackTimeout()) .masterNodeTimeout(request.masterNodeTimeout()); AliasAction[] actions = new AliasAction[2]; - actions[0] = new AliasAction(AliasAction.Type.ADD, targetIndex, request.getSourceAlias()); - actions[1] = new AliasAction(AliasAction.Type.REMOVE, concreteSourceIndex, request.getSourceAlias()); + actions[0] = new AliasAction(AliasAction.Type.ADD, newIndex, request.getSourceAlias()); + actions[1] = new AliasAction(AliasAction.Type.REMOVE, oldIndex, request.getSourceAlias()); updateRequest.actions(actions); return updateRequest; } - static final Pattern INDEX_NAME_PATTERN = Pattern.compile("^.*-(\\d)+$"); static String generateRolloverIndexName(String sourceIndexName) { if (INDEX_NAME_PATTERN.matcher(sourceIndexName).matches()) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index 963080c3122..08565fca9cf 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -44,7 +44,7 @@ public class RestRolloverIndexAction extends BaseRestHandler { @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { if (request.param("alias") == null) { - throw new IllegalArgumentException("no source alias"); + throw new IllegalArgumentException("no alias"); } RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("alias")); if (request.hasContent()) { diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java index 71d6f5a44f7..75a20d05682 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java @@ -34,65 +34,65 @@ import static org.hamcrest.Matchers.equalTo; public class RolloverIT extends ESIntegTestCase { public void testRolloverOnEmptyIndex() throws Exception { - assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); + assertAcked(prepareCreate("test_index-1").addAlias(new Alias("test_alias")).get()); final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); - assertThat(response.getOldIndex(), equalTo("test_index")); - assertThat(response.getNewIndex(), equalTo("test_index-1")); + assertThat(response.getOldIndex(), equalTo("test_index-1")); + assertThat(response.getNewIndex(), equalTo("test_index-2")); assertThat(response.isSimulate(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); assertThat(response.isRolloverIndexCreated(), equalTo(true)); assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); - final IndexMetaData oldIndex = state.metaData().index("test_index"); + final IndexMetaData oldIndex = state.metaData().index("test_index-1"); assertFalse(oldIndex.getAliases().containsKey("test_alias")); - final IndexMetaData newIndex = state.metaData().index("test_index-1"); + final IndexMetaData newIndex = state.metaData().index("test_index-2"); assertTrue(newIndex.getAliases().containsKey("test_alias")); } public void testRollover() throws Exception { - assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); - index("test_index", "type1", "1", "field", "value"); - flush("test_index"); + assertAcked(prepareCreate("test_index-2").addAlias(new Alias("test_alias")).get()); + index("test_index-2", "type1", "1", "field", "value"); + flush("test_index-2"); final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); - assertThat(response.getOldIndex(), equalTo("test_index")); - assertThat(response.getNewIndex(), equalTo("test_index-1")); + assertThat(response.getOldIndex(), equalTo("test_index-2")); + assertThat(response.getNewIndex(), equalTo("test_index-3")); assertThat(response.isSimulate(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); assertThat(response.isRolloverIndexCreated(), equalTo(true)); assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); - final IndexMetaData oldIndex = state.metaData().index("test_index"); + final IndexMetaData oldIndex = state.metaData().index("test_index-2"); assertFalse(oldIndex.getAliases().containsKey("test_alias")); - final IndexMetaData newIndex = state.metaData().index("test_index-1"); + final IndexMetaData newIndex = state.metaData().index("test_index-3"); assertTrue(newIndex.getAliases().containsKey("test_alias")); } public void testRolloverSimulate() throws Exception { - assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); - index("test_index", "type1", "1", "field", "value"); - flush("test_index"); + assertAcked(prepareCreate("test_index-1").addAlias(new Alias("test_alias")).get()); + index("test_index-1", "type1", "1", "field", "value"); + flush("test_index-1"); final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").simulate(true).get(); - assertThat(response.getOldIndex(), equalTo("test_index")); - assertThat(response.getNewIndex(), equalTo("test_index-1")); + assertThat(response.getOldIndex(), equalTo("test_index-1")); + assertThat(response.getNewIndex(), equalTo("test_index-2")); assertThat(response.isSimulate(), equalTo(true)); assertThat(response.isRolledOver(), equalTo(false)); assertThat(response.isRolloverIndexCreated(), equalTo(false)); assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); - final IndexMetaData oldIndex = state.metaData().index("test_index"); + final IndexMetaData oldIndex = state.metaData().index("test_index-1"); assertTrue(oldIndex.getAliases().containsKey("test_alias")); - final IndexMetaData newIndex = state.metaData().index("test_index-1"); + final IndexMetaData newIndex = state.metaData().index("test_index-2"); assertNull(newIndex); } public void testRolloverConditionsNotMet() throws Exception { - assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); - index("test_index", "type1", "1", "field", "value"); - flush("test_index"); + assertAcked(prepareCreate("test_index-0").addAlias(new Alias("test_alias")).get()); + index("test_index-0", "type1", "1", "field", "value"); + flush("test_index-0"); final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias") .addMaxIndexAgeCondition(TimeValue.timeValueHours(4)).get(); - assertThat(response.getOldIndex(), equalTo("test_index")); - assertThat(response.getNewIndex(), equalTo("test_index")); + assertThat(response.getOldIndex(), equalTo("test_index-0")); + assertThat(response.getNewIndex(), equalTo("test_index-0")); assertThat(response.isSimulate(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(false)); assertThat(response.isRolloverIndexCreated(), equalTo(false)); @@ -101,26 +101,26 @@ public class RolloverIT extends ESIntegTestCase { assertThat(conditionEntry.getKey(), equalTo(new MaxAgeCondition(TimeValue.timeValueHours(4)).toString())); assertThat(conditionEntry.getValue(), equalTo(false)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); - final IndexMetaData oldIndex = state.metaData().index("test_index"); + final IndexMetaData oldIndex = state.metaData().index("test_index-0"); assertTrue(oldIndex.getAliases().containsKey("test_alias")); final IndexMetaData newIndex = state.metaData().index("test_index-1"); assertNull(newIndex); } public void testRolloverOnExistingIndex() throws Exception { - assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); - index("test_index", "type1", "1", "field", "value"); + assertAcked(prepareCreate("test_index-0").addAlias(new Alias("test_alias")).get()); + index("test_index-0", "type1", "1", "field", "value"); assertAcked(prepareCreate("test_index-1").get()); index("test_index-1", "type1", "1", "field", "value"); - flush("test_index", "test_index-1"); + flush("test_index-0", "test_index-1"); final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); - assertThat(response.getOldIndex(), equalTo("test_index")); + assertThat(response.getOldIndex(), equalTo("test_index-0")); assertThat(response.getNewIndex(), equalTo("test_index-1")); assertThat(response.isSimulate(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); assertThat(response.isRolloverIndexCreated(), equalTo(false)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); - final IndexMetaData oldIndex = state.metaData().index("test_index"); + final IndexMetaData oldIndex = state.metaData().index("test_index-0"); assertFalse(oldIndex.getAliases().containsKey("test_alias")); final IndexMetaData newIndex = state.metaData().index("test_index-1"); assertTrue(newIndex.getAliases().containsKey("test_alias")); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java index 12e1e90242e..af51645f655 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java @@ -32,10 +32,7 @@ import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.index.shard.DocsStats; import org.elasticsearch.test.ESTestCase; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Set; import static org.elasticsearch.action.admin.indices.rollover.TransportRolloverAction.evaluateConditions; @@ -96,7 +93,7 @@ public class TransportRolloverActionTests extends ESTestCase { String targetIndex = randomAsciiOfLength(10); final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias); final IndicesAliasesClusterStateUpdateRequest updateRequest = - TransportRolloverAction.prepareIndicesAliasesRequest(sourceIndex, targetIndex, rolloverRequest); + TransportRolloverAction.prepareRolloverAliasesUpdateRequest(sourceIndex, targetIndex, rolloverRequest); final AliasAction[] actions = updateRequest.actions(); assertThat(actions.length, equalTo(2)); From 0c6d19c40ca6f375a7d867361c6b5b528b83551a Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Wed, 8 Jun 2016 14:16:06 -0400 Subject: [PATCH 15/87] add body support for create index request --- .../indices/rollover/RolloverRequest.java | 40 +++++++-- .../rollover/RolloverRequestBuilder.java | 17 ++++ .../rollover/TransportRolloverAction.java | 19 ++-- .../admin/indices/rollover/RolloverIT.java | 27 ++++++ .../rollover/RolloverRequestTests.java | 90 +++++++++++++++++++ .../TransportRolloverActionTests.java | 20 ++++- 6 files changed, 201 insertions(+), 12 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index dd1facdb6e2..19659171a67 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.rollover; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.IndicesRequest; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.common.ParseField; @@ -37,6 +38,8 @@ import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; import java.util.HashSet; +import java.util.Map; +import java.util.Objects; import java.util.Set; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -50,13 +53,26 @@ public class RolloverRequest extends AcknowledgedRequest implem private String sourceAlias; private boolean simulate; private Set conditions = new HashSet<>(2); + private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_"); - public static ObjectParser, ParseFieldMatcherSupplier> TLP_PARSER = + public static ObjectParser PARSER = new ObjectParser<>("conditions", null); static { - TLP_PARSER.declareField((parser, conditions, parseFieldMatcherSupplier) -> - Condition.PARSER.parse(parser, conditions, () -> ParseFieldMatcher.EMPTY), + PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> + Condition.PARSER.parse(parser, request.conditions, parseFieldMatcherSupplier), new ParseField("conditions"), ObjectParser.ValueType.OBJECT); + PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> + request.createIndexRequest.settings(parser.map()), + new ParseField("settings"), ObjectParser.ValueType.OBJECT); + PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> { + for (Map.Entry mappingsEntry : parser.map().entrySet()) { + request.createIndexRequest.mapping(mappingsEntry.getKey(), + (Map) mappingsEntry.getValue()); + } + }, new ParseField("mappings"), ObjectParser.ValueType.OBJECT); + PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> + request.createIndexRequest.aliases(parser.map()), + new ParseField("aliases"), ObjectParser.ValueType.OBJECT); } RolloverRequest() {} @@ -67,10 +83,13 @@ public class RolloverRequest extends AcknowledgedRequest implem @Override public ActionRequestValidationException validate() { - ActionRequestValidationException validationException = null; + ActionRequestValidationException validationException = createIndexRequest == null ? null : createIndexRequest.validate(); if (sourceAlias == null) { validationException = addValidationError("source alias is missing", validationException); } + if (createIndexRequest == null) { + validationException = addValidationError("create index request is missing", validationException); + } return validationException; } @@ -83,6 +102,8 @@ public class RolloverRequest extends AcknowledgedRequest implem for (int i = 0; i < size; i++) { this.conditions.add(in.readNamedWriteable(Condition.class)); } + createIndexRequest = new CreateIndexRequest(); + createIndexRequest.readFrom(in); } @Override @@ -94,6 +115,7 @@ public class RolloverRequest extends AcknowledgedRequest implem for (Condition condition : conditions) { out.writeNamedWriteable(condition); } + createIndexRequest.writeTo(out); } @Override @@ -134,11 +156,19 @@ public class RolloverRequest extends AcknowledgedRequest implem return sourceAlias; } + public CreateIndexRequest getCreateIndexRequest() { + return createIndexRequest; + } + + public void setCreateIndexRequest(CreateIndexRequest createIndexRequest) { + this.createIndexRequest = Objects.requireNonNull(createIndexRequest, "create index request must not be null");; + } + public void source(BytesReference source) { XContentType xContentType = XContentFactory.xContentType(source); if (xContentType != null) { try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(source)) { - TLP_PARSER.parse(parser, this.conditions, () -> ParseFieldMatcher.EMPTY); + PARSER.parse(parser, this, () -> ParseFieldMatcher.EMPTY); } catch (IOException e) { throw new ElasticsearchParseException("failed to parse source for rollover index", e); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java index ea495bc6eba..bef680110ab 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -18,8 +18,10 @@ */ package org.elasticsearch.action.admin.indices.rollover; +import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -51,4 +53,19 @@ public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder() { @Override public void onResponse(ClusterStateUpdateResponse response) { @@ -216,10 +215,18 @@ public class TransportRolloverAction extends TransportMasterNodeAction conditions = request.getConditions(); + assertThat(conditions.size(), equalTo(2)); + for (Condition condition : conditions) { + if (condition instanceof MaxAgeCondition) { + MaxAgeCondition maxAgeCondition = (MaxAgeCondition) condition; + assertThat(maxAgeCondition.value.getMillis(), equalTo(TimeValue.timeValueHours(24 * 10).getMillis())); + } else if (condition instanceof MaxDocsCondition) { + MaxDocsCondition maxDocsCondition = (MaxDocsCondition) condition; + assertThat(maxDocsCondition.value, equalTo(100L)); + } else { + fail("unexpected condition " + condition); + } + } + } + + public void testParsingWithIndexSettings() throws Exception { + final RolloverRequest request = new RolloverRequest(randomAsciiOfLength(10)); + final XContentBuilder builder = XContentFactory.jsonBuilder() + .startObject() + .startObject("conditions") + .field("max_age", "10d") + .field("max_docs", 100) + .endObject() + .startObject("mappings") + .startObject("type1") + .startObject("properties") + .startObject("field1") + .field("type", "string") + .field("index", "not_analyzed") + .endObject() + .endObject() + .endObject() + .endObject() + .startObject("settings") + .field("number_of_shards", 10) + .endObject() + .startObject("aliases") + .startObject("alias1").endObject() + .endObject() + .endObject(); + request.source(builder.bytes()); + Set conditions = request.getConditions(); + assertThat(conditions.size(), equalTo(2)); + assertThat(request.getCreateIndexRequest().mappings().size(), equalTo(1)); + assertThat(request.getCreateIndexRequest().aliases().size(), equalTo(1)); + assertThat(request.getCreateIndexRequest().settings().getAsInt("number_of_shards", 0), equalTo(10)); + } +} diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java index af51645f655..28c0a6e3787 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.rollover; import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest; +import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest; import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -86,7 +87,6 @@ public class TransportRolloverActionTests extends ESTestCase { } } - public void testCreateUpdateAliasRequest() throws Exception { String sourceAlias = randomAsciiOfLength(10); String sourceIndex = randomAsciiOfLength(10); @@ -158,4 +158,22 @@ public class TransportRolloverActionTests extends ESTestCase { assertThat(TransportRolloverAction.generateRolloverIndexName("index-name-1"), equalTo("index-name-2")); assertThat(TransportRolloverAction.generateRolloverIndexName("index-name-2"), equalTo("index-name-3")); } + + public void testCreateIndexRequest() throws Exception { + String alias = randomAsciiOfLength(10); + String rolloverIndex = randomAsciiOfLength(10); + final RolloverRequest rolloverRequest = new RolloverRequest(alias); + final Settings settings = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .build(); + rolloverRequest.getCreateIndexRequest().settings(settings); + final CreateIndexClusterStateUpdateRequest createIndexRequest = + TransportRolloverAction.prepareCreateIndexRequest(rolloverIndex, rolloverRequest); + assertThat(createIndexRequest.settings(), equalTo(settings)); + assertThat(createIndexRequest.index(), equalTo(rolloverIndex)); + assertThat(createIndexRequest.cause(), equalTo("rollover_index")); + } } From ae3eb15caaaf61f3c0b627aad1bc22fcd71ec04e Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Wed, 8 Jun 2016 15:03:35 -0400 Subject: [PATCH 16/87] fix rest tests --- .../indices/rollover/RolloverRequest.java | 24 +++++------ .../rollover/RolloverRequestBuilder.java | 4 +- .../rollover/TransportRolloverAction.java | 8 ++-- .../client/support/AbstractClient.java | 4 +- .../indices/RestRolloverIndexAction.java | 10 ++--- .../rest-api-spec/api/indices.rollover.json | 8 ++-- .../test/indices.rollover/10_basic.yaml | 41 +++++++++++-------- 7 files changed, 52 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index 19659171a67..a16a6db83ca 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -50,7 +50,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; */ public class RolloverRequest extends AcknowledgedRequest implements IndicesRequest { - private String sourceAlias; + private String alias; private boolean simulate; private Set conditions = new HashSet<>(2); private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_"); @@ -77,15 +77,15 @@ public class RolloverRequest extends AcknowledgedRequest implem RolloverRequest() {} - public RolloverRequest(String sourceAlias) { - this.sourceAlias = sourceAlias; + public RolloverRequest(String alias) { + this.alias = alias; } @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = createIndexRequest == null ? null : createIndexRequest.validate(); - if (sourceAlias == null) { - validationException = addValidationError("source alias is missing", validationException); + if (alias == null) { + validationException = addValidationError("index alias is missing", validationException); } if (createIndexRequest == null) { validationException = addValidationError("create index request is missing", validationException); @@ -96,7 +96,7 @@ public class RolloverRequest extends AcknowledgedRequest implem @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - sourceAlias = in.readString(); + alias = in.readString(); simulate = in.readBoolean(); int size = in.readVInt(); for (int i = 0; i < size; i++) { @@ -109,7 +109,7 @@ public class RolloverRequest extends AcknowledgedRequest implem @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeString(sourceAlias); + out.writeString(alias); out.writeBoolean(simulate); out.writeVInt(conditions.size()); for (Condition condition : conditions) { @@ -120,7 +120,7 @@ public class RolloverRequest extends AcknowledgedRequest implem @Override public String[] indices() { - return new String[] {sourceAlias}; + return new String[] {alias}; } @Override @@ -128,8 +128,8 @@ public class RolloverRequest extends AcknowledgedRequest implem return IndicesOptions.strictSingleIndexNoExpandForbidClosed(); } - public void setSourceAlias(String sourceAlias) { - this.sourceAlias = sourceAlias; + public void setAlias(String alias) { + this.alias = alias; } public void simulate(boolean simulate) { @@ -152,8 +152,8 @@ public class RolloverRequest extends AcknowledgedRequest implem return conditions; } - public String getSourceAlias() { - return sourceAlias; + public String getAlias() { + return alias; } public CreateIndexRequest getCreateIndexRequest() { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java index bef680110ab..dd6e22dae70 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -34,8 +34,8 @@ public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder listener) { final MetaData metaData = state.metaData(); validate(metaData, rolloverRequest); - final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(rolloverRequest.getSourceAlias()); + final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(rolloverRequest.getAlias()); final IndexMetaData indexMetaData = aliasOrIndex.getIndices().get(0); final String sourceIndexName = indexMetaData.getIndex().getName(); client.admin().indices().prepareStats(sourceIndexName).clear().setDocs(true).execute( @@ -173,8 +173,8 @@ public class TransportRolloverAction extends TransportMasterNodeAction Date: Wed, 8 Jun 2016 18:32:22 -0400 Subject: [PATCH 17/87] add documentation --- .../admin/indices/rollover/Condition.java | 13 ++- .../indices/rollover/MaxAgeCondition.java | 4 + .../indices/rollover/MaxDocsCondition.java | 4 + .../indices/rollover/RolloverRequest.java | 55 +++++++----- .../rollover/RolloverRequestBuilder.java | 3 - .../indices/rollover/RolloverResponse.java | 18 ++++ .../rollover/TransportRolloverAction.java | 2 +- docs/reference/indices.asciidoc | 1 + .../reference/indices/rollover-index.asciidoc | 84 +++++++++++++++++++ 9 files changed, 159 insertions(+), 25 deletions(-) create mode 100644 docs/reference/indices/rollover-index.asciidoc diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java index 12c3ef45993..8d9b48f2000 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java @@ -27,12 +27,17 @@ import org.elasticsearch.common.xcontent.ObjectParser; import java.util.Set; +/** + * Base class for rollover request conditions + */ public abstract class Condition implements NamedWriteable { + public static ObjectParser, ParseFieldMatcherSupplier> PARSER = new ObjectParser<>("conditions", null); static { PARSER.declareString((conditions, s) -> - conditions.add(new MaxAgeCondition(TimeValue.parseTimeValue(s, MaxAgeCondition.NAME))), new ParseField(MaxAgeCondition.NAME)); + conditions.add(new MaxAgeCondition(TimeValue.parseTimeValue(s, MaxAgeCondition.NAME))), + new ParseField(MaxAgeCondition.NAME)); PARSER.declareLong((conditions, value) -> conditions.add(new MaxDocsCondition(value)), new ParseField(MaxDocsCondition.NAME)); } @@ -51,6 +56,9 @@ public abstract class Condition implements NamedWriteable { return "[" + name + ": " + value + "]"; } + /** + * Holder for index stats used to evaluate conditions + */ public static class Stats { public final long numDocs; public final long indexCreated; @@ -61,6 +69,9 @@ public abstract class Condition implements NamedWriteable { } } + /** + * Holder for evaluated condition result + */ public static class Result { public final Condition condition; public final boolean matched; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxAgeCondition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxAgeCondition.java index 0a7e85bb129..ee0641bbe18 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxAgeCondition.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxAgeCondition.java @@ -25,6 +25,10 @@ import org.elasticsearch.common.unit.TimeValue; import java.io.IOException; +/** + * Condition for index maximum age. Evaluates to true + * when the index is at least {@link #value} old + */ public class MaxAgeCondition extends Condition { public final static String NAME = "max_age"; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxDocsCondition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxDocsCondition.java index e1c599c23d4..8b327929124 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxDocsCondition.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/MaxDocsCondition.java @@ -24,6 +24,10 @@ import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; +/** + * Condition for maximum index docs. Evaluates to true + * when the index has at least {@link #value} docs + */ public class MaxDocsCondition extends Condition { public final static String NAME = "max_docs"; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index a16a6db83ca..abae56cb5fb 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -45,24 +45,18 @@ import java.util.Set; import static org.elasticsearch.action.ValidateActions.addValidationError; /** - * Request class to swap index under an alias given some predicates - * TODO: documentation + * Request class to swap index under an alias upon satisfying conditions */ public class RolloverRequest extends AcknowledgedRequest implements IndicesRequest { - private String alias; - private boolean simulate; - private Set conditions = new HashSet<>(2); - private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_"); - public static ObjectParser PARSER = new ObjectParser<>("conditions", null); static { PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> - Condition.PARSER.parse(parser, request.conditions, parseFieldMatcherSupplier), + Condition.PARSER.parse(parser, request.conditions, parseFieldMatcherSupplier), new ParseField("conditions"), ObjectParser.ValueType.OBJECT); PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> - request.createIndexRequest.settings(parser.map()), + request.createIndexRequest.settings(parser.map()), new ParseField("settings"), ObjectParser.ValueType.OBJECT); PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> { for (Map.Entry mappingsEntry : parser.map().entrySet()) { @@ -71,10 +65,15 @@ public class RolloverRequest extends AcknowledgedRequest implem } }, new ParseField("mappings"), ObjectParser.ValueType.OBJECT); PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> - request.createIndexRequest.aliases(parser.map()), + request.createIndexRequest.aliases(parser.map()), new ParseField("aliases"), ObjectParser.ValueType.OBJECT); } + private String alias; + private boolean simulate; + private Set conditions = new HashSet<>(2); + private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_"); + RolloverRequest() {} public RolloverRequest(String alias) { @@ -128,42 +127,58 @@ public class RolloverRequest extends AcknowledgedRequest implem return IndicesOptions.strictSingleIndexNoExpandForbidClosed(); } + /** + * Sets the alias to rollover to another index + */ public void setAlias(String alias) { this.alias = alias; } + /** + * Sets if the rollover should not be executed when conditions are met + */ public void simulate(boolean simulate) { this.simulate = simulate; } + /** + * Adds condition to check if the index is at least age old + */ public void addMaxIndexAgeCondition(TimeValue age) { this.conditions.add(new MaxAgeCondition(age)); } - public void addMaxIndexDocsCondition(long docs) { - this.conditions.add(new MaxDocsCondition(docs)); + /** + * Adds condition to check if the index has at least numDocs + */ + public void addMaxIndexDocsCondition(long numDocs) { + this.conditions.add(new MaxDocsCondition(numDocs)); } - public boolean isSimulate() { + /** + * Sets rollover index creation request to override index settings when + * the rolled over index has to be created + */ + public void setCreateIndexRequest(CreateIndexRequest createIndexRequest) { + this.createIndexRequest = Objects.requireNonNull(createIndexRequest, "create index request must not be null");; + } + + boolean isSimulate() { return simulate; } - public Set getConditions() { + Set getConditions() { return conditions; } - public String getAlias() { + String getAlias() { return alias; } - public CreateIndexRequest getCreateIndexRequest() { + CreateIndexRequest getCreateIndexRequest() { return createIndexRequest; } - public void setCreateIndexRequest(CreateIndexRequest createIndexRequest) { - this.createIndexRequest = Objects.requireNonNull(createIndexRequest, "create index request must not be null");; - } - public void source(BytesReference source) { XContentType xContentType = XContentFactory.xContentType(source); if (xContentType != null) { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java index dd6e22dae70..cfce9d24ad4 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -25,9 +25,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -/** - * TODO: Documentation - */ public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder { public RolloverRequestBuilder(ElasticsearchClient client, RolloverAction action) { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java index fbca8af99cc..14feec0248f 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java @@ -56,26 +56,44 @@ public final class RolloverResponse extends ActionResponse implements ToXContent .collect(Collectors.toSet()); } + /** + * Returns the name of the index that the request alias was pointing to + */ public String getOldIndex() { return oldIndex; } + /** + * Returns the name of the index that the request alias currently points to + */ public String getNewIndex() { return newIndex; } + /** + * Returns the statuses of all the request conditions + */ public Set> getConditionStatus() { return conditionStatus; } + /** + * Returns if the rollover execution was skipped even when conditions were met + */ public boolean isSimulate() { return simulate; } + /** + * Returns if the rollover was not simulated and the conditions were met + */ public boolean isRolledOver() { return rolledOver; } + /** + * Returns if the rollover index had to be explicitly created + */ public boolean isRolloverIndexCreated() { return rolloverIndexCreated; } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index 61ae2852f68..0cd29b84056 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -51,7 +51,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; /** - * Main class to swap the index pointed to by an alias, given some predicates + * Main class to swap the index pointed to by an alias, given some conditions */ public class TransportRolloverAction extends TransportMasterNodeAction { diff --git a/docs/reference/indices.asciidoc b/docs/reference/indices.asciidoc index e49340fe15f..cad1a1477bd 100644 --- a/docs/reference/indices.asciidoc +++ b/docs/reference/indices.asciidoc @@ -16,6 +16,7 @@ index settings, aliases, mappings, and index templates. * <> * <> * <> +* <> [float] [[mapping-management]] diff --git a/docs/reference/indices/rollover-index.asciidoc b/docs/reference/indices/rollover-index.asciidoc new file mode 100644 index 00000000000..2c553a4e0f1 --- /dev/null +++ b/docs/reference/indices/rollover-index.asciidoc @@ -0,0 +1,84 @@ +[[indices-rollover-index]] +== Rollover Index + +The rollover index API allows to switch the index pointed to by an alias given some predicates. +In order to rollover an index, the provided alias has to point to a single index. Upon satisfying +any of the predicates, the alias is switched to point to a new index, creating the index if it +does not exist. The rollover API requires the old concrete index name to have `{index_prefix}-{num}` +format, as rollover index name is generated following `{index_prefix}-{num+1}` format. + +This API is syntactic sugar for changing the index pointed to by an alias given some predicate. + +The rollover API must be used against an alias that points to a single index: + +[source,js] +-------------------------------------------------- +$ curl -XPUT 'http://localhost:9200/index-1/' -d '{ + "aliases" : { + "index_alias": {} + } +}' +-------------------------------------------------- + +To rollover `index_alias` to point to a new index: + +[source,js] +-------------------------------------------------- +$ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{ + "conditions" : { + "max_age": "7d", <1> + "max_docs": 1000 <2> + } +}' +-------------------------------------------------- +<1> Sets a condition that the index has to be at least 7 days old +<2> Sets a condition that the index has to have at least a 1000 documents + +The API call above switches the index pointed to by `index_alias` from `index-1` to `index-2`, if any +of the conditions are met. If `index-2` does not exist, it is created (using matching <> +if available). The API call returns immediately if none of the conditions are met. + +The `_rollover` API is similar to <> and accepts `settings`, `mappings` and `aliases` +to override the index create request for a non-existent rolled over index. + +[source,js] +-------------------------------------------------- +$ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{ + "conditions" : { + "max_age": "7d", + "max_docs": 1000 + }, + "settings": { <1> + "index.number_of_shards": 2 + } +}' +-------------------------------------------------- +<1> Set settings to override matching index template, `mappings` and `aliases` can also be provided. + +Using the http `GET` method for the API runs the rollover in simulated mode, where request conditions can be +checked without performing the actual rollover. Setting `simulate=true` as a request parameter also runs +the request in simulated mode. + +An example response for the index rollover API: + +[source,js] +-------------------------------------------------- +{ + "old_index": "index-1", <1> + "new_index": "index-2", <2> + "rolled_over": true, <3> + "simulated": false, <4> + "rollover_index_created": true, <5> + "conditions": { <6> + "[max_age: 7d]": true, + "[max_docs: 1000]": true + } +} +-------------------------------------------------- +<1> name of the index the alias was pointing to +<2> name of the index the alias currently points to +<3> whether the alias switch was successful +<4> whether the rollover was dry run +<5> whether the rolled over index had to be explicitly created +<6> status of the evaluated request conditions + From 9027e8a719d81ebc9fc19f4b99bbb5dcec1d9def Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Thu, 9 Jun 2016 11:55:10 -0400 Subject: [PATCH 18/87] renamed simulated mode to dry_run mode --- .../indices/rollover/RolloverRequest.java | 14 +++++++------- .../rollover/RolloverRequestBuilder.java | 4 ++-- .../indices/rollover/RolloverResponse.java | 18 +++++++++--------- .../rollover/TransportRolloverAction.java | 2 +- .../admin/indices/RestRolloverIndexAction.java | 3 +-- .../admin/indices/rollover/RolloverIT.java | 16 ++++++++-------- docs/reference/indices/rollover-index.asciidoc | 7 +++---- 7 files changed, 31 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index abae56cb5fb..10d780a005b 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -70,7 +70,7 @@ public class RolloverRequest extends AcknowledgedRequest implem } private String alias; - private boolean simulate; + private boolean dryRun; private Set conditions = new HashSet<>(2); private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_"); @@ -96,7 +96,7 @@ public class RolloverRequest extends AcknowledgedRequest implem public void readFrom(StreamInput in) throws IOException { super.readFrom(in); alias = in.readString(); - simulate = in.readBoolean(); + dryRun = in.readBoolean(); int size = in.readVInt(); for (int i = 0; i < size; i++) { this.conditions.add(in.readNamedWriteable(Condition.class)); @@ -109,7 +109,7 @@ public class RolloverRequest extends AcknowledgedRequest implem public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(alias); - out.writeBoolean(simulate); + out.writeBoolean(dryRun); out.writeVInt(conditions.size()); for (Condition condition : conditions) { out.writeNamedWriteable(condition); @@ -137,8 +137,8 @@ public class RolloverRequest extends AcknowledgedRequest implem /** * Sets if the rollover should not be executed when conditions are met */ - public void simulate(boolean simulate) { - this.simulate = simulate; + public void dryRun(boolean dryRun) { + this.dryRun = dryRun; } /** @@ -163,8 +163,8 @@ public class RolloverRequest extends AcknowledgedRequest implem this.createIndexRequest = Objects.requireNonNull(createIndexRequest, "create index request must not be null");; } - boolean isSimulate() { - return simulate; + boolean isDryRun() { + return dryRun; } Set getConditions() { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java index cfce9d24ad4..8beebc2e516 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -46,8 +46,8 @@ public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder> conditionStatus; - private boolean simulate; + private boolean dryRun; private boolean rolledOver; private boolean rolloverIndexCreated; @@ -45,10 +45,10 @@ public final class RolloverResponse extends ActionResponse implements ToXContent } RolloverResponse(String oldIndex, String newIndex, Set conditionResults, - boolean simulate, boolean rolledOver, boolean rolloverIndexCreated) { + boolean dryRun, boolean rolledOver, boolean rolloverIndexCreated) { this.oldIndex = oldIndex; this.newIndex = newIndex; - this.simulate = simulate; + this.dryRun = dryRun; this.rolledOver = rolledOver; this.rolloverIndexCreated = rolloverIndexCreated; this.conditionStatus = conditionResults.stream() @@ -80,8 +80,8 @@ public final class RolloverResponse extends ActionResponse implements ToXContent /** * Returns if the rollover execution was skipped even when conditions were met */ - public boolean isSimulate() { - return simulate; + public boolean isDryRun() { + return dryRun; } /** @@ -111,7 +111,7 @@ public final class RolloverResponse extends ActionResponse implements ToXContent conditions.add(new AbstractMap.SimpleEntry<>(condition, satisfied)); } conditionStatus = conditions; - simulate = in.readBoolean(); + dryRun = in.readBoolean(); rolledOver = in.readBoolean(); rolloverIndexCreated = in.readBoolean(); } @@ -126,7 +126,7 @@ public final class RolloverResponse extends ActionResponse implements ToXContent out.writeString(entry.getKey()); out.writeBoolean(entry.getValue()); } - out.writeBoolean(simulate); + out.writeBoolean(dryRun); out.writeBoolean(rolledOver); out.writeBoolean(rolloverIndexCreated); } @@ -136,7 +136,7 @@ public final class RolloverResponse extends ActionResponse implements ToXContent builder.field(Fields.OLD_INDEX, oldIndex); builder.field(Fields.NEW_INDEX, newIndex); builder.field(Fields.ROLLED_OVER, rolledOver); - builder.field(Fields.SIMULATED, simulate); + builder.field(Fields.DRY_RUN, dryRun); builder.field(Fields.ROLLOVER_INDEX_CREATED, rolloverIndexCreated); builder.startObject(Fields.CONDITIONS); for (Map.Entry entry : conditionStatus) { @@ -149,7 +149,7 @@ public final class RolloverResponse extends ActionResponse implements ToXContent static final class Fields { static final String NEW_INDEX = "new_index"; static final String OLD_INDEX = "old_index"; - static final String SIMULATED = "simulated"; + static final String DRY_RUN = "dry_run"; static final String ROLLED_OVER = "rolled_over"; static final String ROLLOVER_INDEX_CREATED = "rollover_index_created"; static final String CONDITIONS = "conditions"; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index 0cd29b84056..baf743466ee 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -106,7 +106,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction conditionResults = evaluateConditions(rolloverRequest.getConditions(), statsResponse.getTotal().getDocs(), metaData.index(sourceIndexName)); final String rolloverIndexName = generateRolloverIndexName(sourceIndexName); - if (rolloverRequest.isSimulate()) { + if (rolloverRequest.isDryRun()) { listener.onResponse( new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, true, false, false)); diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index cccdf22d1d4..635e22ce83c 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -38,7 +38,6 @@ public class RestRolloverIndexAction extends BaseRestHandler { public RestRolloverIndexAction(Settings settings, RestController controller, Client client) { super(settings, client); controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover", this); - controller.registerHandler(RestRequest.Method.GET, "/{index}/_rollover", this); } @SuppressWarnings({"unchecked"}) @@ -48,7 +47,7 @@ public class RestRolloverIndexAction extends BaseRestHandler { if (request.hasContent()) { rolloverIndexRequest.source(request.content()); } - rolloverIndexRequest.simulate(request.method() == RestRequest.Method.GET || request.paramAsBoolean("simulate", false)); + rolloverIndexRequest.dryRun(request.paramAsBoolean("dry_run", false)); rolloverIndexRequest.timeout(request.paramAsTime("timeout", rolloverIndexRequest.timeout())); rolloverIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", rolloverIndexRequest.masterNodeTimeout())); client.admin().indices().rolloverIndex(rolloverIndexRequest, new RestToXContentListener<>(channel)); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java index bf28bdfdbc8..112fe91eaaf 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java @@ -39,7 +39,7 @@ public class RolloverIT extends ESIntegTestCase { final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); assertThat(response.getOldIndex(), equalTo("test_index-1")); assertThat(response.getNewIndex(), equalTo("test_index-2")); - assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); assertThat(response.isRolloverIndexCreated(), equalTo(true)); assertThat(response.getConditionStatus().size(), equalTo(0)); @@ -57,7 +57,7 @@ public class RolloverIT extends ESIntegTestCase { final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); assertThat(response.getOldIndex(), equalTo("test_index-2")); assertThat(response.getNewIndex(), equalTo("test_index-3")); - assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); assertThat(response.isRolloverIndexCreated(), equalTo(true)); assertThat(response.getConditionStatus().size(), equalTo(0)); @@ -80,7 +80,7 @@ public class RolloverIT extends ESIntegTestCase { .settings(settings).alias(new Alias("extra_alias")).get(); assertThat(response.getOldIndex(), equalTo("test_index-2")); assertThat(response.getNewIndex(), equalTo("test_index-3")); - assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); assertThat(response.isRolloverIndexCreated(), equalTo(true)); assertThat(response.getConditionStatus().size(), equalTo(0)); @@ -94,14 +94,14 @@ public class RolloverIT extends ESIntegTestCase { assertTrue(newIndex.getAliases().containsKey("extra_alias")); } - public void testRolloverSimulate() throws Exception { + public void testRolloverDryRun() throws Exception { assertAcked(prepareCreate("test_index-1").addAlias(new Alias("test_alias")).get()); index("test_index-1", "type1", "1", "field", "value"); flush("test_index-1"); - final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").simulate(true).get(); + final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").dryRun(true).get(); assertThat(response.getOldIndex(), equalTo("test_index-1")); assertThat(response.getNewIndex(), equalTo("test_index-2")); - assertThat(response.isSimulate(), equalTo(true)); + assertThat(response.isDryRun(), equalTo(true)); assertThat(response.isRolledOver(), equalTo(false)); assertThat(response.isRolloverIndexCreated(), equalTo(false)); assertThat(response.getConditionStatus().size(), equalTo(0)); @@ -120,7 +120,7 @@ public class RolloverIT extends ESIntegTestCase { .addMaxIndexAgeCondition(TimeValue.timeValueHours(4)).get(); assertThat(response.getOldIndex(), equalTo("test_index-0")); assertThat(response.getNewIndex(), equalTo("test_index-0")); - assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(false)); assertThat(response.isRolloverIndexCreated(), equalTo(false)); assertThat(response.getConditionStatus().size(), equalTo(1)); @@ -143,7 +143,7 @@ public class RolloverIT extends ESIntegTestCase { final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); assertThat(response.getOldIndex(), equalTo("test_index-0")); assertThat(response.getNewIndex(), equalTo("test_index-1")); - assertThat(response.isSimulate(), equalTo(false)); + assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); assertThat(response.isRolloverIndexCreated(), equalTo(false)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); diff --git a/docs/reference/indices/rollover-index.asciidoc b/docs/reference/indices/rollover-index.asciidoc index 2c553a4e0f1..f4c228b9870 100644 --- a/docs/reference/indices/rollover-index.asciidoc +++ b/docs/reference/indices/rollover-index.asciidoc @@ -55,9 +55,8 @@ $ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{ -------------------------------------------------- <1> Set settings to override matching index template, `mappings` and `aliases` can also be provided. -Using the http `GET` method for the API runs the rollover in simulated mode, where request conditions can be -checked without performing the actual rollover. Setting `simulate=true` as a request parameter also runs -the request in simulated mode. +The rollover API supports `dry_run` mode, where request conditions can be checked without performing the +actual rollover. The `dry_run` mode can be enabled by setting `dry_run=true` as a request parameter. An example response for the index rollover API: @@ -67,7 +66,7 @@ An example response for the index rollover API: "old_index": "index-1", <1> "new_index": "index-2", <2> "rolled_over": true, <3> - "simulated": false, <4> + "dry_run": false, <4> "rollover_index_created": true, <5> "conditions": { <6> "[max_age: 7d]": true, From a9f24ea2dcc5ec15c8778e3df7fea172caa422f0 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Thu, 9 Jun 2016 12:38:12 -0400 Subject: [PATCH 19/87] fail rollover request if rollover index already exists --- .../indices/rollover/RolloverResponse.java | 15 +--- .../rollover/TransportRolloverAction.java | 70 ++++++++----------- .../admin/indices/rollover/RolloverIT.java | 23 ++---- .../reference/indices/rollover-index.asciidoc | 21 +++--- .../test/indices.rollover/10_basic.yaml | 3 +- 5 files changed, 49 insertions(+), 83 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java index 4bfd7905129..d3a36f7d561 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java @@ -39,18 +39,16 @@ public final class RolloverResponse extends ActionResponse implements ToXContent private Set> conditionStatus; private boolean dryRun; private boolean rolledOver; - private boolean rolloverIndexCreated; RolloverResponse() { } RolloverResponse(String oldIndex, String newIndex, Set conditionResults, - boolean dryRun, boolean rolledOver, boolean rolloverIndexCreated) { + boolean dryRun, boolean rolledOver) { this.oldIndex = oldIndex; this.newIndex = newIndex; this.dryRun = dryRun; this.rolledOver = rolledOver; - this.rolloverIndexCreated = rolloverIndexCreated; this.conditionStatus = conditionResults.stream() .map(result -> new AbstractMap.SimpleEntry<>(result.condition.toString(), result.matched)) .collect(Collectors.toSet()); @@ -91,13 +89,6 @@ public final class RolloverResponse extends ActionResponse implements ToXContent return rolledOver; } - /** - * Returns if the rollover index had to be explicitly created - */ - public boolean isRolloverIndexCreated() { - return rolloverIndexCreated; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); @@ -113,7 +104,6 @@ public final class RolloverResponse extends ActionResponse implements ToXContent conditionStatus = conditions; dryRun = in.readBoolean(); rolledOver = in.readBoolean(); - rolloverIndexCreated = in.readBoolean(); } @Override @@ -128,7 +118,6 @@ public final class RolloverResponse extends ActionResponse implements ToXContent } out.writeBoolean(dryRun); out.writeBoolean(rolledOver); - out.writeBoolean(rolloverIndexCreated); } @Override @@ -137,7 +126,6 @@ public final class RolloverResponse extends ActionResponse implements ToXContent builder.field(Fields.NEW_INDEX, newIndex); builder.field(Fields.ROLLED_OVER, rolledOver); builder.field(Fields.DRY_RUN, dryRun); - builder.field(Fields.ROLLOVER_INDEX_CREATED, rolloverIndexCreated); builder.startObject(Fields.CONDITIONS); for (Map.Entry entry : conditionStatus) { builder.field(entry.getKey(), entry.getValue()); @@ -151,7 +139,6 @@ public final class RolloverResponse extends ActionResponse implements ToXContent static final String OLD_INDEX = "old_index"; static final String DRY_RUN = "dry_run"; static final String ROLLED_OVER = "rolled_over"; - static final String ROLLOVER_INDEX_CREATED = "rollover_index_created"; static final String CONDITIONS = "conditions"; } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index baf743466ee..51623f11966 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -43,6 +43,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.DocsStats; +import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -108,36 +109,42 @@ public class TransportRolloverAction extends TransportMasterNodeAction result.matched)) { - boolean createRolloverIndex = metaData.index(rolloverIndexName) == null; - final RolloverResponse rolloverResponse = - new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, false, true, - createRolloverIndex); - if (createRolloverIndex) { - createIndexService.createIndex(prepareCreateIndexRequest(rolloverIndexName, rolloverRequest), - new ActionListener() { - @Override - public void onResponse(ClusterStateUpdateResponse response) { - rollover(rolloverRequest, rolloverResponse, listener); - } + createIndexService.createIndex(prepareCreateIndexRequest(rolloverIndexName, rolloverRequest), + new ActionListener() { + @Override + public void onResponse(ClusterStateUpdateResponse response) { + // switch the alias to point to the newly created index + indexAliasesService.indicesAliases( + prepareRolloverAliasesUpdateRequest(sourceIndexName, rolloverIndexName, + rolloverRequest), + new ActionListener() { + @Override + public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { + listener.onResponse( + new RolloverResponse(sourceIndexName, rolloverIndexName, + conditionResults, false, true)); + } - @Override - public void onFailure(Throwable t) { - listener.onFailure(t); - } - }); - } else { - rollover(rolloverRequest, rolloverResponse, listener); - } + @Override + public void onFailure(Throwable e) { + listener.onFailure(e); + } + }); + } + + @Override + public void onFailure(Throwable t) { + listener.onFailure(t); + } + }); } else { // conditions not met listener.onResponse( - new RolloverResponse(sourceIndexName, sourceIndexName, conditionResults, false, false, - false) + new RolloverResponse(sourceIndexName, sourceIndexName, conditionResults, false, false) ); } } @@ -150,23 +157,6 @@ public class TransportRolloverAction extends TransportMasterNodeAction listener) { - indexAliasesService.indicesAliases( - prepareRolloverAliasesUpdateRequest(response.getOldIndex(), response.getNewIndex(), request), - new ActionListener() { - @Override - public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { - listener.onResponse(response); - } - - @Override - public void onFailure(Throwable e) { - listener.onFailure(e); - } - }); - } - static IndicesAliasesClusterStateUpdateRequest prepareRolloverAliasesUpdateRequest(String oldIndex, String newIndex, RolloverRequest request) { final IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest() diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java index 112fe91eaaf..a47c91acc0f 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java @@ -24,6 +24,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.test.ESIntegTestCase; import java.util.Map; @@ -41,7 +42,6 @@ public class RolloverIT extends ESIntegTestCase { assertThat(response.getNewIndex(), equalTo("test_index-2")); assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); - assertThat(response.isRolloverIndexCreated(), equalTo(true)); assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index-1"); @@ -59,7 +59,6 @@ public class RolloverIT extends ESIntegTestCase { assertThat(response.getNewIndex(), equalTo("test_index-3")); assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); - assertThat(response.isRolloverIndexCreated(), equalTo(true)); assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index-2"); @@ -82,7 +81,6 @@ public class RolloverIT extends ESIntegTestCase { assertThat(response.getNewIndex(), equalTo("test_index-3")); assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(true)); - assertThat(response.isRolloverIndexCreated(), equalTo(true)); assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index-2"); @@ -103,7 +101,6 @@ public class RolloverIT extends ESIntegTestCase { assertThat(response.getNewIndex(), equalTo("test_index-2")); assertThat(response.isDryRun(), equalTo(true)); assertThat(response.isRolledOver(), equalTo(false)); - assertThat(response.isRolloverIndexCreated(), equalTo(false)); assertThat(response.getConditionStatus().size(), equalTo(0)); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final IndexMetaData oldIndex = state.metaData().index("test_index-1"); @@ -122,7 +119,6 @@ public class RolloverIT extends ESIntegTestCase { assertThat(response.getNewIndex(), equalTo("test_index-0")); assertThat(response.isDryRun(), equalTo(false)); assertThat(response.isRolledOver(), equalTo(false)); - assertThat(response.isRolloverIndexCreated(), equalTo(false)); assertThat(response.getConditionStatus().size(), equalTo(1)); final Map.Entry conditionEntry = response.getConditionStatus().iterator().next(); assertThat(conditionEntry.getKey(), equalTo(new MaxAgeCondition(TimeValue.timeValueHours(4)).toString())); @@ -140,16 +136,11 @@ public class RolloverIT extends ESIntegTestCase { assertAcked(prepareCreate("test_index-1").get()); index("test_index-1", "type1", "1", "field", "value"); flush("test_index-0", "test_index-1"); - final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get(); - assertThat(response.getOldIndex(), equalTo("test_index-0")); - assertThat(response.getNewIndex(), equalTo("test_index-1")); - assertThat(response.isDryRun(), equalTo(false)); - assertThat(response.isRolledOver(), equalTo(true)); - assertThat(response.isRolloverIndexCreated(), equalTo(false)); - final ClusterState state = client().admin().cluster().prepareState().get().getState(); - final IndexMetaData oldIndex = state.metaData().index("test_index-0"); - assertFalse(oldIndex.getAliases().containsKey("test_alias")); - final IndexMetaData newIndex = state.metaData().index("test_index-1"); - assertTrue(newIndex.getAliases().containsKey("test_alias")); + try { + client().admin().indices().prepareRolloverIndex("test_alias").get(); + fail("expected failure due to existing rollover index"); + } catch (IndexAlreadyExistsException e) { + assertThat(e.getIndex().getName(), equalTo("test_index-1")); + } } } diff --git a/docs/reference/indices/rollover-index.asciidoc b/docs/reference/indices/rollover-index.asciidoc index f4c228b9870..9deb8cc3c7f 100644 --- a/docs/reference/indices/rollover-index.asciidoc +++ b/docs/reference/indices/rollover-index.asciidoc @@ -3,9 +3,10 @@ The rollover index API allows to switch the index pointed to by an alias given some predicates. In order to rollover an index, the provided alias has to point to a single index. Upon satisfying -any of the predicates, the alias is switched to point to a new index, creating the index if it -does not exist. The rollover API requires the old concrete index name to have `{index_prefix}-{num}` -format, as rollover index name is generated following `{index_prefix}-{num+1}` format. +any of the predicates, the alias is switched to point to the rollover index, if the rollover index +already exists, the rollover fails. The rollover API requires the old concrete index name to have +`{index_prefix}-{num}` format, as rollover index name is generated following `{index_prefix}-{num+1}` +format. This API is syntactic sugar for changing the index pointed to by an alias given some predicate. @@ -35,11 +36,11 @@ $ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{ <2> Sets a condition that the index has to have at least a 1000 documents The API call above switches the index pointed to by `index_alias` from `index-1` to `index-2`, if any -of the conditions are met. If `index-2` does not exist, it is created (using matching <> -if available). The API call returns immediately if none of the conditions are met. +of the conditions are met. `index-2` is created (using matching <> if available). +The API call returns immediately if none of the conditions are met. -The `_rollover` API is similar to <> and accepts `settings`, `mappings` and `aliases` -to override the index create request for a non-existent rolled over index. +The `_rollover` API is similar to <> and accepts `settings`, `mappings` and +`aliases` to override the index create request for the rollover index. [source,js] -------------------------------------------------- @@ -67,8 +68,7 @@ An example response for the index rollover API: "new_index": "index-2", <2> "rolled_over": true, <3> "dry_run": false, <4> - "rollover_index_created": true, <5> - "conditions": { <6> + "conditions": { <5> "[max_age: 7d]": true, "[max_docs: 1000]": true } @@ -78,6 +78,5 @@ An example response for the index rollover API: <2> name of the index the alias currently points to <3> whether the alias switch was successful <4> whether the rollover was dry run -<5> whether the rolled over index had to be explicitly created -<6> status of the evaluated request conditions +<5> status of the evaluated request conditions diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml index 8252a7f0254..c60907fb416 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml @@ -39,8 +39,7 @@ - match: { old_index: logs-1 } - match: { new_index: logs-2 } - match: { rolled_over: true } - - match: { rollover_index_created: true } - - match: { simulated: false } + - match: { dry_run: false } - match: { conditions: { "[max_docs: 1]": true } } # ensure new index is created From 756af81b0019061bbf498459eed50b06a0c3f4cc Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Thu, 9 Jun 2016 12:53:24 -0400 Subject: [PATCH 20/87] change rollover rest-api placeholder name --- .../main/resources/rest-api-spec/api/indices.rollover.json | 6 +++--- .../rest-api-spec/test/indices.rollover/10_basic.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json index ec66d48116a..7ba7d9cd29c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json @@ -3,10 +3,10 @@ "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html", "methods": ["POST"], "url": { - "path": "/{index}/_rollover", - "paths": ["/{index}/_rollover"], + "path": "/{alias}/_rollover", + "paths": ["/{alias}/_rollover"], "parts": { - "index": { + "alias": { "type" : "string", "required" : true, "description" : "The name of the alias to rollover" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml index c60907fb416..647907614fa 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/10_basic.yaml @@ -31,7 +31,7 @@ # perform alias rollover - do: indices.rollover: - index: "logs_search" + alias: "logs_search" body: conditions: max_docs: 1 From 41d31541a645dd3052d36a1596867a3ed0ea946f Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Thu, 9 Jun 2016 13:43:19 -0400 Subject: [PATCH 21/87] Allow users to override the name for the rollover index --- .../indices/rollover/RolloverRequest.java | 16 +++++++++++++++- .../rollover/RolloverRequestBuilder.java | 9 +++++++-- .../rollover/TransportRolloverAction.java | 4 +++- .../metadata/MetaDataMappingService.java | 2 +- .../admin/indices/RestRolloverIndexAction.java | 3 ++- .../admin/indices/rollover/RolloverIT.java | 18 ++++++++++++++++++ .../indices/rollover/RolloverRequestTests.java | 4 ++-- .../rollover/TransportRolloverActionTests.java | 15 +++++++++------ docs/reference/indices/rollover-index.asciidoc | 18 ++++++++++-------- .../rest-api-spec/api/indices.rollover.json | 9 +++++++-- 10 files changed, 74 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index 10d780a005b..9e98418f184 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -70,14 +70,16 @@ public class RolloverRequest extends AcknowledgedRequest implem } private String alias; + private String newIndexName; private boolean dryRun; private Set conditions = new HashSet<>(2); private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_"); RolloverRequest() {} - public RolloverRequest(String alias) { + public RolloverRequest(String alias, String newIndexName) { this.alias = alias; + this.newIndexName = newIndexName; } @Override @@ -96,6 +98,7 @@ public class RolloverRequest extends AcknowledgedRequest implem public void readFrom(StreamInput in) throws IOException { super.readFrom(in); alias = in.readString(); + newIndexName = in.readOptionalString(); dryRun = in.readBoolean(); int size = in.readVInt(); for (int i = 0; i < size; i++) { @@ -109,6 +112,7 @@ public class RolloverRequest extends AcknowledgedRequest implem public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(alias); + out.writeOptionalString(newIndexName); out.writeBoolean(dryRun); out.writeVInt(conditions.size()); for (Condition condition : conditions) { @@ -134,6 +138,12 @@ public class RolloverRequest extends AcknowledgedRequest implem this.alias = alias; } + /** + * Sets the alias to rollover to another index + */ + public void setNewIndexName(String newIndexName) { + this.newIndexName = newIndexName; + } /** * Sets if the rollover should not be executed when conditions are met */ @@ -175,6 +185,10 @@ public class RolloverRequest extends AcknowledgedRequest implem return alias; } + String getNewIndexName() { + return newIndexName; + } + CreateIndexRequest getCreateIndexRequest() { return createIndexRequest; } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java index 8beebc2e516..e9b4351fc5d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -31,8 +31,13 @@ public class RolloverRequestBuilder extends MasterNodeOperationRequestBuilder conditionResults = evaluateConditions(rolloverRequest.getConditions(), statsResponse.getTotal().getDocs(), metaData.index(sourceIndexName)); - final String rolloverIndexName = generateRolloverIndexName(sourceIndexName); + final String rolloverIndexName = (rolloverRequest.getNewIndexName() != null) + ? rolloverRequest.getNewIndexName() + : generateRolloverIndexName(sourceIndexName); if (rolloverRequest.isDryRun()) { listener.onResponse( new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, true, false)); diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index a41d02d28fa..a98f2148da8 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -299,7 +299,7 @@ public class MetaDataMappingService extends AbstractComponent { assert mappingType != null; if (!MapperService.DEFAULT_MAPPING.equals(mappingType) && mappingType.charAt(0) == '_') { - throw new InvalidTypeNameException("Document mapping type name can't start with '_'"); + throw new InvalidTypeNameException("Document mapping type name can't start with '_', found: [" + mappingType + "]"); } MetaData.Builder builder = MetaData.builder(metaData); for (Tuple toUpdate : updateList) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index 635e22ce83c..7eecaaa738c 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -38,12 +38,13 @@ public class RestRolloverIndexAction extends BaseRestHandler { public RestRolloverIndexAction(Settings settings, RestController controller, Client client) { super(settings, client); controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover", this); + controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover/{new_index}", this); } @SuppressWarnings({"unchecked"}) @Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { - RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index")); + RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index")); if (request.hasContent()) { rolloverIndexRequest.source(request.content()); } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java index a47c91acc0f..b45383c47e4 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIT.java @@ -130,6 +130,24 @@ public class RolloverIT extends ESIntegTestCase { assertNull(newIndex); } + public void testRolloverWithNewIndexName() throws Exception { + assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get()); + index("test_index", "type1", "1", "field", "value"); + flush("test_index"); + final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias") + .setNewIndexName("test_new_index").get(); + assertThat(response.getOldIndex(), equalTo("test_index")); + assertThat(response.getNewIndex(), equalTo("test_new_index")); + assertThat(response.isDryRun(), equalTo(false)); + assertThat(response.isRolledOver(), equalTo(true)); + assertThat(response.getConditionStatus().size(), equalTo(0)); + final ClusterState state = client().admin().cluster().prepareState().get().getState(); + final IndexMetaData oldIndex = state.metaData().index("test_index"); + assertFalse(oldIndex.getAliases().containsKey("test_alias")); + final IndexMetaData newIndex = state.metaData().index("test_new_index"); + assertTrue(newIndex.getAliases().containsKey("test_alias")); + } + public void testRolloverOnExistingIndex() throws Exception { assertAcked(prepareCreate("test_index-0").addAlias(new Alias("test_alias")).get()); index("test_index-0", "type1", "1", "field", "value"); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java index 754e4c419bd..7f4db3b8409 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java @@ -31,7 +31,7 @@ import static org.hamcrest.Matchers.equalTo; public class RolloverRequestTests extends ESTestCase { public void testConditionsParsing() throws Exception { - final RolloverRequest request = new RolloverRequest(randomAsciiOfLength(10)); + final RolloverRequest request = new RolloverRequest(randomAsciiOfLength(10), randomAsciiOfLength(10)); final XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .startObject("conditions") @@ -56,7 +56,7 @@ public class RolloverRequestTests extends ESTestCase { } public void testParsingWithIndexSettings() throws Exception { - final RolloverRequest request = new RolloverRequest(randomAsciiOfLength(10)); + final RolloverRequest request = new RolloverRequest(randomAsciiOfLength(10), randomAsciiOfLength(10)); final XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .startObject("conditions") diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java index 28c0a6e3787..7d163630afb 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java @@ -91,7 +91,7 @@ public class TransportRolloverActionTests extends ESTestCase { String sourceAlias = randomAsciiOfLength(10); String sourceIndex = randomAsciiOfLength(10); String targetIndex = randomAsciiOfLength(10); - final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias); + final RolloverRequest rolloverRequest = new RolloverRequest(sourceAlias, targetIndex); final IndicesAliasesClusterStateUpdateRequest updateRequest = TransportRolloverAction.prepareRolloverAliasesUpdateRequest(sourceIndex, targetIndex, rolloverRequest); @@ -137,13 +137,16 @@ public class TransportRolloverActionTests extends ESTestCase { ).build(); expectThrows(IllegalArgumentException.class, () -> - TransportRolloverAction.validate(metaData, new RolloverRequest(aliasWithMultipleIndices))); + TransportRolloverAction.validate(metaData, new RolloverRequest(aliasWithMultipleIndices, + randomAsciiOfLength(10)))); expectThrows(IllegalArgumentException.class, () -> - TransportRolloverAction.validate(metaData, new RolloverRequest(randomFrom(index1, index2)))); + TransportRolloverAction.validate(metaData, new RolloverRequest(randomFrom(index1, index2), + randomAsciiOfLength(10)))); expectThrows(IllegalArgumentException.class, () -> - TransportRolloverAction.validate(metaData, new RolloverRequest(randomAsciiOfLength(5))) + TransportRolloverAction.validate(metaData, new RolloverRequest(randomAsciiOfLength(5), + randomAsciiOfLength(10))) ); - TransportRolloverAction.validate(metaData, new RolloverRequest(alias)); + TransportRolloverAction.validate(metaData, new RolloverRequest(alias, randomAsciiOfLength(10))); } public void testGenerateRolloverIndexName() throws Exception { @@ -162,7 +165,7 @@ public class TransportRolloverActionTests extends ESTestCase { public void testCreateIndexRequest() throws Exception { String alias = randomAsciiOfLength(10); String rolloverIndex = randomAsciiOfLength(10); - final RolloverRequest rolloverRequest = new RolloverRequest(alias); + final RolloverRequest rolloverRequest = new RolloverRequest(alias, randomAsciiOfLength(10)); final Settings settings = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) diff --git a/docs/reference/indices/rollover-index.asciidoc b/docs/reference/indices/rollover-index.asciidoc index 9deb8cc3c7f..b5c845f7360 100644 --- a/docs/reference/indices/rollover-index.asciidoc +++ b/docs/reference/indices/rollover-index.asciidoc @@ -4,9 +4,7 @@ The rollover index API allows to switch the index pointed to by an alias given some predicates. In order to rollover an index, the provided alias has to point to a single index. Upon satisfying any of the predicates, the alias is switched to point to the rollover index, if the rollover index -already exists, the rollover fails. The rollover API requires the old concrete index name to have -`{index_prefix}-{num}` format, as rollover index name is generated following `{index_prefix}-{num+1}` -format. +already exists, the rollover fails. This API is syntactic sugar for changing the index pointed to by an alias given some predicate. @@ -14,18 +12,18 @@ The rollover API must be used against an alias that points to a single index: [source,js] -------------------------------------------------- -$ curl -XPUT 'http://localhost:9200/index-1/' -d '{ +$ curl -XPUT 'http://localhost:9200/index1' -d '{ "aliases" : { "index_alias": {} } }' -------------------------------------------------- -To rollover `index_alias` to point to a new index: +To rollover `index_alias` to point to a new index `index2`: [source,js] -------------------------------------------------- -$ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{ +$ curl -XPOST 'http://localhost:9200/index_alias/_rollover/index2' -d '{ "conditions" : { "max_age": "7d", <1> "max_docs": 1000 <2> @@ -35,10 +33,14 @@ $ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{ <1> Sets a condition that the index has to be at least 7 days old <2> Sets a condition that the index has to have at least a 1000 documents -The API call above switches the index pointed to by `index_alias` from `index-1` to `index-2`, if any -of the conditions are met. `index-2` is created (using matching <> if available). +The API call above switches the index pointed to by `index_alias` from `index1` to `index2`, if any +of the conditions are met. `index2` is created (using matching <> if available). The API call returns immediately if none of the conditions are met. +The rollover API can be used without specifying the name for the new index. In this case, the API requires +the old concrete index name to have `{index_prefix}-{num}` format, as rollover index name is generated +following `{index_prefix}-{num+1}` format. + The `_rollover` API is similar to <> and accepts `settings`, `mappings` and `aliases` to override the index create request for the rollover index. diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json index 7ba7d9cd29c..d3660c4a679 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.rollover.json @@ -3,13 +3,18 @@ "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html", "methods": ["POST"], "url": { - "path": "/{alias}/_rollover", - "paths": ["/{alias}/_rollover"], + "path": "/{alias}/_rollover}", + "paths": ["/{alias}/_rollover", "/{alias}/_rollover/{new_index}"], "parts": { "alias": { "type" : "string", "required" : true, "description" : "The name of the alias to rollover" + }, + "new_index": { + "type" : "string", + "required" : false, + "description" : "The name of the rollover index" } }, "params": { From 62f98767eb1ac37c70465770562a89302670be56 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Fri, 10 Jun 2016 12:02:36 -0300 Subject: [PATCH 22/87] removed redundant Fields class --- .../indices/rollover/RolloverResponse.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java index d3a36f7d561..0f254e825da 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java @@ -34,6 +34,12 @@ import java.util.stream.Collectors; public final class RolloverResponse extends ActionResponse implements ToXContent { + private static final String NEW_INDEX = "new_index"; + private static final String OLD_INDEX = "old_index"; + private static final String DRY_RUN = "dry_run"; + private static final String ROLLED_OVER = "rolled_over"; + private static final String CONDITIONS = "conditions"; + private String oldIndex; private String newIndex; private Set> conditionStatus; @@ -122,23 +128,15 @@ public final class RolloverResponse extends ActionResponse implements ToXContent @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(Fields.OLD_INDEX, oldIndex); - builder.field(Fields.NEW_INDEX, newIndex); - builder.field(Fields.ROLLED_OVER, rolledOver); - builder.field(Fields.DRY_RUN, dryRun); - builder.startObject(Fields.CONDITIONS); + builder.field(OLD_INDEX, oldIndex); + builder.field(NEW_INDEX, newIndex); + builder.field(ROLLED_OVER, rolledOver); + builder.field(DRY_RUN, dryRun); + builder.startObject(CONDITIONS); for (Map.Entry entry : conditionStatus) { builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); return builder; } - - static final class Fields { - static final String NEW_INDEX = "new_index"; - static final String OLD_INDEX = "old_index"; - static final String DRY_RUN = "dry_run"; - static final String ROLLED_OVER = "rolled_over"; - static final String CONDITIONS = "conditions"; - } } From df4a959d6c7b1bca1fe9ce7561635f835c519d24 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Fri, 10 Jun 2016 12:06:50 -0300 Subject: [PATCH 23/87] removed support for customs from create index request --- .../action/admin/indices/rollover/TransportRolloverAction.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index 533e24a2ad5..952448af5e7 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -217,7 +217,6 @@ public class TransportRolloverAction extends TransportMasterNodeAction Date: Wed, 15 Jun 2016 14:57:17 -0400 Subject: [PATCH 24/87] update docs --- .../reference/indices/rollover-index.asciidoc | 163 +++++++++++------- 1 file changed, 96 insertions(+), 67 deletions(-) diff --git a/docs/reference/indices/rollover-index.asciidoc b/docs/reference/indices/rollover-index.asciidoc index b5c845f7360..35ad327f181 100644 --- a/docs/reference/indices/rollover-index.asciidoc +++ b/docs/reference/indices/rollover-index.asciidoc @@ -1,84 +1,113 @@ [[indices-rollover-index]] == Rollover Index -The rollover index API allows to switch the index pointed to by an alias given some predicates. -In order to rollover an index, the provided alias has to point to a single index. Upon satisfying -any of the predicates, the alias is switched to point to the rollover index, if the rollover index -already exists, the rollover fails. +The rollover index API rolls an alias over to a new index when the existing +index is considered to be too large or too old. -This API is syntactic sugar for changing the index pointed to by an alias given some predicate. +The API accepts a single alias name and a list of `conditions`. The alias +must point to a single index only. If the index satisfies the specified +conditions then a new index is created and the alias is switched to point to +the new alias. -The rollover API must be used against an alias that points to a single index: [source,js] -------------------------------------------------- -$ curl -XPUT 'http://localhost:9200/index1' -d '{ - "aliases" : { - "index_alias": {} - } -}' +PUT /logs-0001 <1> +{ + "aliases": { + "logs_write": {} + } +} + +POST logs_write/_rollover <2> +{ + "conditions": { + "max_age": "7d", + "max_docs": 1000 + } +} -------------------------------------------------- +// CONSOLE +<1> Creates an index called `logs-0001` with the alias `logs_write`. +<2> If the index pointed to by `logs_write` was created 7 or more days ago, or + contains 1,000 or more documents, then the `logs-0002` index is created + and the `logs_write` alias is updated to point to `logs-0002`. -To rollover `index_alias` to point to a new index `index2`: - -[source,js] --------------------------------------------------- -$ curl -XPOST 'http://localhost:9200/index_alias/_rollover/index2' -d '{ - "conditions" : { - "max_age": "7d", <1> - "max_docs": 1000 <2> - } -}' --------------------------------------------------- -<1> Sets a condition that the index has to be at least 7 days old -<2> Sets a condition that the index has to have at least a 1000 documents - -The API call above switches the index pointed to by `index_alias` from `index1` to `index2`, if any -of the conditions are met. `index2` is created (using matching <> if available). -The API call returns immediately if none of the conditions are met. - -The rollover API can be used without specifying the name for the new index. In this case, the API requires -the old concrete index name to have `{index_prefix}-{num}` format, as rollover index name is generated -following `{index_prefix}-{num+1}` format. - -The `_rollover` API is similar to <> and accepts `settings`, `mappings` and -`aliases` to override the index create request for the rollover index. - -[source,js] --------------------------------------------------- -$ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{ - "conditions" : { - "max_age": "7d", - "max_docs": 1000 - }, - "settings": { <1> - "index.number_of_shards": 2 - } -}' --------------------------------------------------- -<1> Set settings to override matching index template, `mappings` and `aliases` can also be provided. - -The rollover API supports `dry_run` mode, where request conditions can be checked without performing the -actual rollover. The `dry_run` mode can be enabled by setting `dry_run=true` as a request parameter. - -An example response for the index rollover API: +The above request might return the following response: [source,js] -------------------------------------------------- { - "old_index": "index-1", <1> - "new_index": "index-2", <2> - "rolled_over": true, <3> - "dry_run": false, <4> - "conditions": { <5> - "[max_age: 7d]": true, - "[max_docs: 1000]": true - } + "old_index": "logs-0001", + "new_index": "logs-0002", + "rolled_over": true, <1> + "dry_run": false, <2> + "conditions": { <3> + "[max_age: 7d]": false, + "[max_docs: 1000]": true + } } -------------------------------------------------- -<1> name of the index the alias was pointing to -<2> name of the index the alias currently points to -<3> whether the alias switch was successful -<4> whether the rollover was dry run -<5> status of the evaluated request conditions + <1> Whether the index was rolled over. + <2> Whether the rollover was dry run. + <3> The result of each condition. + +[float] +=== Naming the new index + +If the name of the existing index ends with `-` and a number -- e.g. +`logs-0001` -- then the name of the new index will follow the same pattern, +just incrementing the number (`logs-0002`). + +If the old name doesn't match this pattern then you must specify the name for +the new index as follows: + +[source,js] +-------------------------------------------------- +POST my_alias/_rollover/my_new_index_name +{...} +-------------------------------------------------- + +[float] +=== Defining the new index + +The settings, mappings, and aliases for the new index will be taken from any +matching <>. Additionally, the body of the +request accepts `settings`, `mappings`, and `aliases` just like the +<> API, which will override any values +set in matching index templates: + +[source,js] +-------------------------------------------------- +POST /logs_writes/_rollover +{ + "conditions" : { + "max_age": "7d", + "max_docs": 1000 + }, + "settings": { <1> + "index.number_of_shards": 2 <1> + } +} +-------------------------------------------------- +// CONSOLE +<1> Set settings to override matching index template, `mappings` and `aliases` can also be provided. + + [float] + === Dry run + +The rollover API supports `dry_run` mode, where request conditions can be +checked without performing the actual rollover: + +[source,js] +-------------------------------------------------- +POST /logs_writes/_rollover?dry_run +{ + "conditions" : { + "max_age": "7d", + "max_docs": 1000 + } +} +-------------------------------------------------- +// CONSOLE From b036d238f5561283049de38b0e9e7a6a256139bc Mon Sep 17 00:00:00 2001 From: David Pilato Date: Thu, 16 Jun 2016 05:51:39 +0200 Subject: [PATCH 25/87] Fix typo --- .../rest-api-spec/test/repository_s3/20_repository.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/repository-s3/src/test/resources/rest-api-spec/test/repository_s3/20_repository.yaml b/plugins/repository-s3/src/test/resources/rest-api-spec/test/repository_s3/20_repository.yaml index eb909f91f1d..17294986d2d 100644 --- a/plugins/repository-s3/src/test/resources/rest-api-spec/test/repository_s3/20_repository.yaml +++ b/plugins/repository-s3/src/test/resources/rest-api-spec/test/repository_s3/20_repository.yaml @@ -14,7 +14,7 @@ canned_acl: "public-read" storage_class: "standard" - # Get repositry + # Get repository - do: snapshot.get_repository: repository: test_repo_s3_1 From 615920df2e121bc70d52f49e39e93a934c5c0e3c Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Fri, 17 Jun 2016 00:03:28 -0400 Subject: [PATCH 26/87] update docs --- .../reference/indices/rollover-index.asciidoc | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/reference/indices/rollover-index.asciidoc b/docs/reference/indices/rollover-index.asciidoc index 35ad327f181..6879470267f 100644 --- a/docs/reference/indices/rollover-index.asciidoc +++ b/docs/reference/indices/rollover-index.asciidoc @@ -79,7 +79,14 @@ set in matching index templates: [source,js] -------------------------------------------------- -POST /logs_writes/_rollover +PUT /logs-0001 +{ + "aliases": { + "logs_write": {} + } +} + +POST logs_write/_rollover { "conditions" : { "max_age": "7d", @@ -91,7 +98,8 @@ POST /logs_writes/_rollover } -------------------------------------------------- // CONSOLE -<1> Set settings to override matching index template, `mappings` and `aliases` can also be provided. +<1> Set settings to override matching index template, `mappings` and `aliases` + can also be provided. [float] === Dry run @@ -101,7 +109,14 @@ checked without performing the actual rollover: [source,js] -------------------------------------------------- -POST /logs_writes/_rollover?dry_run +PUT /logs-0001 +{ + "aliases": { + "logs_write": {} + } +} + +POST logs_write/_rollover?dry_run { "conditions" : { "max_age": "7d", From 529c2ca13f3e689dcd3e4f856070db5dc125c605 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 17 Jun 2016 12:17:48 +0200 Subject: [PATCH 27/87] Add did-you-mean for plugin cli This commit adds error messages like: `Unknown plugin xpack, did you mean [x-pack]?` Closes #18896 --- .../plugins/InstallPluginCommand.java | 25 ++++++++++++++++++- .../plugins/InstallPluginCommandTests.java | 16 ++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java index 643998f19c2..51bb3b6b82f 100644 --- a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java +++ b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java @@ -45,11 +45,14 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.TreeSet; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import joptsimple.OptionSet; import joptsimple.OptionSpec; +import org.apache.lucene.search.spell.LevensteinDistance; +import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.IOUtils; import org.elasticsearch.Version; import org.elasticsearch.bootstrap.JarHell; @@ -57,6 +60,7 @@ import org.elasticsearch.cli.ExitCodes; import org.elasticsearch.cli.SettingCommand; import org.elasticsearch.cli.Terminal; import org.elasticsearch.cli.UserError; +import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.hash.MessageDigests; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.Settings; @@ -239,12 +243,31 @@ class InstallPluginCommand extends SettingCommand { // fall back to plain old URL if (pluginId.contains(":/") == false) { // definitely not a valid url, so assume it is a plugin name - throw new UserError(ExitCodes.USAGE, "Unknown plugin " + pluginId); + List plugins = checkMisspelledPlugin(pluginId); + String msg = "Unknown plugin " + pluginId; + if (plugins.isEmpty() == false) { + msg += ", did you mean " + (plugins.size() == 1 ? "[" + plugins.get(0) + "]": "any of " + plugins.toString()) + "?"; + } + throw new UserError(ExitCodes.USAGE, msg); } terminal.println("-> Downloading " + URLDecoder.decode(pluginId, "UTF-8")); return downloadZip(terminal, pluginId, tmpDir); } + /** Returns all the official plugin names that look similar to pluginId. **/ + private List checkMisspelledPlugin(String pluginId) { + LevensteinDistance ld = new LevensteinDistance(); + List> scoredKeys = new ArrayList<>(); + for (String officialPlugin : OFFICIAL_PLUGINS) { + float distance = ld.getDistance(pluginId, officialPlugin); + if (distance > 0.7f) { + scoredKeys.add(new Tuple<>(distance, officialPlugin)); + } + } + CollectionUtil.timSort(scoredKeys, (a, b) -> b.v1().compareTo(a.v1())); + return scoredKeys.stream().map((a) -> a.v2()).collect(Collectors.toList()); + } + /** Downloads a zip from the url, into a temp file under the given temp dir. */ private Path downloadZip(Terminal terminal, String urlString, Path tmpDir) throws IOException { terminal.println(VERBOSE, "Retrieving zip from " + urlString); diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java index fdf52da2634..2b9b6ec6ab9 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java @@ -67,6 +67,7 @@ import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -567,6 +568,21 @@ public class InstallPluginCommandTests extends ESTestCase { assertTrue(terminal.getOutput(), terminal.getOutput().contains("x-pack")); } + public void testInstallMisspelledOfficialPlugins() throws Exception { + Tuple env = createEnv(fs, temp); + UserError e = expectThrows(UserError.class, () -> installPlugin("xpack", env.v1())); + assertThat(e.getMessage(), containsString("Unknown plugin xpack, did you mean [x-pack]?")); + + e = expectThrows(UserError.class, () -> installPlugin("analysis-smartnc", env.v1())); + assertThat(e.getMessage(), containsString("Unknown plugin analysis-smartnc, did you mean [analysis-smartcn]?")); + + e = expectThrows(UserError.class, () -> installPlugin("repository", env.v1())); + assertThat(e.getMessage(), containsString("Unknown plugin repository, did you mean any of [repository-s3, repository-gcs]?")); + + e = expectThrows(UserError.class, () -> installPlugin("unknown_plugin", env.v1())); + assertThat(e.getMessage(), containsString("Unknown plugin unknown_plugin")); + } + // TODO: test batch flag? // TODO: test checksum (need maven/official below) // TODO: test maven, official, and staging install...need tests with fixtures... From 712e387058a85406ddc4e706dba7e2caed54ce2e Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 1 Jun 2016 10:44:16 +0200 Subject: [PATCH 28/87] Rename PipelineAggregatorBuilder to PipelineAggregationBuilder. This is a follow-up to #18377. --- .../action/search/SearchRequestBuilder.java | 4 +- .../elasticsearch/search/SearchModule.java | 86 +++++++++---------- .../AbstractAggregationBuilder.java | 2 +- .../aggregations/AggregationBuilder.java | 2 +- .../aggregations/AggregatorFactories.java | 52 +++++------ .../aggregations/AggregatorParsers.java | 2 +- ...r.java => PipelineAggregationBuilder.java} | 10 +-- ...> AbstractPipelineAggregationBuilder.java} | 20 ++--- .../aggregations/pipeline/BucketHelpers.java | 4 +- .../pipeline/PipelineAggregator.java | 6 +- .../pipeline/PipelineAggregatorBuilders.java | 86 +++++++++---------- .../bucketmetrics/BucketMetricsParser.java | 6 +- ...ketMetricsPipelineAggregationBuilder.java} | 18 ++-- ... AvgBucketPipelineAggregationBuilder.java} | 18 ++-- ... MaxBucketPipelineAggregationBuilder.java} | 18 ++-- ... MinBucketPipelineAggregationBuilder.java} | 18 ++-- ...ilesBucketPipelineAggregationBuilder.java} | 26 +++--- ...tatsBucketPipelineAggregationBuilder.java} | 18 ++-- .../extended/ExtendedStatsBucketParser.java | 6 +- ...tatsBucketPipelineAggregationBuilder.java} | 20 ++--- ... SumBucketPipelineAggregationBuilder.java} | 18 ++-- ...cketScriptPipelineAggregationBuilder.java} | 22 ++--- ...etSelectorPipelineAggregationBuilder.java} | 20 ++--- ...ulativeSumPipelineAggregationBuilder.java} | 22 ++--- ...DerivativePipelineAggregationBuilder.java} | 30 +++---- ... => MovAvgPipelineAggregationBuilder.java} | 35 ++++---- .../pipeline/movavg/models/EwmaModel.java | 10 +-- .../movavg/models/HoltLinearModel.java | 10 +-- .../movavg/models/HoltWintersModel.java | 10 +-- .../pipeline/movavg/models/LinearModel.java | 6 +- .../pipeline/movavg/models/SimpleModel.java | 6 +- ...SerialDiffPipelineAggregationBuilder.java} | 22 ++--- .../search/builder/SearchSourceBuilder.java | 4 +- .../BasePipelineAggregationTestCase.java | 10 +-- .../pipeline/BucketScriptTests.java | 8 +- .../pipeline/BucketSelectorTests.java | 8 +- .../pipeline/CumulativeSumTests.java | 8 +- .../pipeline/DerivativeTests.java | 8 +- .../pipeline/SerialDifferenceTests.java | 8 +- .../AbstractBucketMetricsTestCase.java | 2 +- .../bucketmetrics/AvgBucketTests.java | 8 +- .../ExtendedStatsBucketTests.java | 10 +-- .../bucketmetrics/MaxBucketTests.java | 8 +- .../bucketmetrics/MinBucketTests.java | 8 +- .../bucketmetrics/PercentilesBucketTests.java | 10 +-- .../bucketmetrics/StatsBucketTests.java | 8 +- .../bucketmetrics/SumBucketTests.java | 8 +- .../pipeline/moving/avg/MovAvgTests.java | 14 +-- .../percolator/PercolateRequestBuilder.java | 6 +- .../percolator/PercolateSourceBuilder.java | 8 +- 50 files changed, 389 insertions(+), 388 deletions(-) rename core/src/main/java/org/elasticsearch/search/aggregations/{PipelineAggregatorBuilder.java => PipelineAggregationBuilder.java} (86%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/{AbstractPipelineAggregatorBuilder.java => AbstractPipelineAggregationBuilder.java} (86%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/{BucketMetricsPipelineAggregatorBuilder.java => BucketMetricsPipelineAggregationBuilder.java} (86%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/{AvgBucketPipelineAggregatorBuilder.java => AvgBucketPipelineAggregationBuilder.java} (78%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/{MaxBucketPipelineAggregatorBuilder.java => MaxBucketPipelineAggregationBuilder.java} (78%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/{MinBucketPipelineAggregatorBuilder.java => MinBucketPipelineAggregationBuilder.java} (78%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/{PercentilesBucketPipelineAggregatorBuilder.java => PercentilesBucketPipelineAggregationBuilder.java} (83%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/{StatsBucketPipelineAggregatorBuilder.java => StatsBucketPipelineAggregationBuilder.java} (79%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/{ExtendedStatsBucketPipelineAggregatorBuilder.java => ExtendedStatsBucketPipelineAggregationBuilder.java} (81%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/{SumBucketPipelineAggregatorBuilder.java => SumBucketPipelineAggregationBuilder.java} (78%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/{BucketScriptPipelineAggregatorBuilder.java => BucketScriptPipelineAggregationBuilder.java} (91%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/{BucketSelectorPipelineAggregatorBuilder.java => BucketSelectorPipelineAggregationBuilder.java} (90%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/{CumulativeSumPipelineAggregatorBuilder.java => CumulativeSumPipelineAggregationBuilder.java} (88%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/{DerivativePipelineAggregatorBuilder.java => DerivativePipelineAggregationBuilder.java} (89%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/{MovAvgPipelineAggregatorBuilder.java => MovAvgPipelineAggregationBuilder.java} (92%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/{SerialDiffPipelineAggregatorBuilder.java => SerialDiffPipelineAggregationBuilder.java} (90%) diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java index 173c15ec1a5..47be65521d6 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java @@ -29,7 +29,7 @@ import org.elasticsearch.script.Script; import org.elasticsearch.script.Template; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.aggregations.AggregationBuilder; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.slice.SliceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.highlight.HighlightBuilder; @@ -387,7 +387,7 @@ public class SearchRequestBuilder extends ActionRequestBuilder reader, + public void registerPipelineAggregation(Writeable.Reader reader, PipelineAggregator.Parser aggregationParser, ParseField aggregationName) { pipelineAggregationParserRegistry.register(aggregationParser, aggregationName); - namedWriteableRegistry.register(PipelineAggregatorBuilder.class, aggregationName.getPreferredName(), reader); + namedWriteableRegistry.register(PipelineAggregationBuilder.class, aggregationName.getPreferredName(), reader); } @Override @@ -500,33 +500,33 @@ public class SearchModule extends AbstractModule { ScriptedMetricAggregationBuilder.AGGREGATION_NAME_FIELD); registerAggregation(ChildrenAggregationBuilder::new, ChildrenAggregationBuilder::parse, ChildrenAggregationBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(DerivativePipelineAggregatorBuilder::new, DerivativePipelineAggregatorBuilder::parse, - DerivativePipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(MaxBucketPipelineAggregatorBuilder::new, MaxBucketPipelineAggregatorBuilder.PARSER, - MaxBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(MinBucketPipelineAggregatorBuilder::new, MinBucketPipelineAggregatorBuilder.PARSER, - MinBucketPipelineAggregatorBuilder.AGGREGATION_FIELD_NAME); - registerPipelineAggregation(AvgBucketPipelineAggregatorBuilder::new, AvgBucketPipelineAggregatorBuilder.PARSER, - AvgBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(SumBucketPipelineAggregatorBuilder::new, SumBucketPipelineAggregatorBuilder.PARSER, - SumBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(StatsBucketPipelineAggregatorBuilder::new, StatsBucketPipelineAggregatorBuilder.PARSER, - StatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(ExtendedStatsBucketPipelineAggregatorBuilder::new, new ExtendedStatsBucketParser(), - ExtendedStatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(PercentilesBucketPipelineAggregatorBuilder::new, PercentilesBucketPipelineAggregatorBuilder.PARSER, - PercentilesBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(MovAvgPipelineAggregatorBuilder::new, - (n, c) -> MovAvgPipelineAggregatorBuilder.parse(movingAverageModelParserRegistry, n, c), - MovAvgPipelineAggregatorBuilder.AGGREGATION_FIELD_NAME); - registerPipelineAggregation(CumulativeSumPipelineAggregatorBuilder::new, CumulativeSumPipelineAggregatorBuilder::parse, - CumulativeSumPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(BucketScriptPipelineAggregatorBuilder::new, BucketScriptPipelineAggregatorBuilder::parse, - BucketScriptPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(BucketSelectorPipelineAggregatorBuilder::new, BucketSelectorPipelineAggregatorBuilder::parse, - BucketSelectorPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineAggregation(SerialDiffPipelineAggregatorBuilder::new, SerialDiffPipelineAggregatorBuilder::parse, - SerialDiffPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(DerivativePipelineAggregationBuilder::new, DerivativePipelineAggregationBuilder::parse, + DerivativePipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(MaxBucketPipelineAggregationBuilder::new, MaxBucketPipelineAggregationBuilder.PARSER, + MaxBucketPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(MinBucketPipelineAggregationBuilder::new, MinBucketPipelineAggregationBuilder.PARSER, + MinBucketPipelineAggregationBuilder.AGGREGATION_FIELD_NAME); + registerPipelineAggregation(AvgBucketPipelineAggregationBuilder::new, AvgBucketPipelineAggregationBuilder.PARSER, + AvgBucketPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(SumBucketPipelineAggregationBuilder::new, SumBucketPipelineAggregationBuilder.PARSER, + SumBucketPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(StatsBucketPipelineAggregationBuilder::new, StatsBucketPipelineAggregationBuilder.PARSER, + StatsBucketPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(ExtendedStatsBucketPipelineAggregationBuilder::new, new ExtendedStatsBucketParser(), + ExtendedStatsBucketPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(PercentilesBucketPipelineAggregationBuilder::new, PercentilesBucketPipelineAggregationBuilder.PARSER, + PercentilesBucketPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(MovAvgPipelineAggregationBuilder::new, + (n, c) -> MovAvgPipelineAggregationBuilder.parse(movingAverageModelParserRegistry, n, c), + MovAvgPipelineAggregationBuilder.AGGREGATION_FIELD_NAME); + registerPipelineAggregation(CumulativeSumPipelineAggregationBuilder::new, CumulativeSumPipelineAggregationBuilder::parse, + CumulativeSumPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(BucketScriptPipelineAggregationBuilder::new, BucketScriptPipelineAggregationBuilder::parse, + BucketScriptPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(BucketSelectorPipelineAggregationBuilder::new, BucketSelectorPipelineAggregationBuilder::parse, + BucketSelectorPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); + registerPipelineAggregation(SerialDiffPipelineAggregationBuilder::new, SerialDiffPipelineAggregationBuilder::parse, + SerialDiffPipelineAggregationBuilder.AGGREGATION_NAME_FIELD); bind(AggregatorParsers.class).toInstance(aggregatorParsers); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AbstractAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/AbstractAggregationBuilder.java index ef54cdf0ef5..e84d7684304 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AbstractAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AbstractAggregationBuilder.java @@ -80,7 +80,7 @@ public abstract class AbstractAggregationBuilder[0], - new ArrayList()); + new ArrayList()); private AggregatorFactory parent; private AggregatorFactory[] factories; - private List pipelineAggregatorFactories; + private List pipelineAggregatorFactories; public static Builder builder() { return new Builder(); } private AggregatorFactories(AggregatorFactory parent, AggregatorFactory[] factories, - List pipelineAggregators) { + List pipelineAggregators) { this.parent = parent; this.factories = factories; this.pipelineAggregatorFactories = pipelineAggregators; @@ -65,7 +65,7 @@ public class AggregatorFactories { public List createPipelineAggregators() throws IOException { List pipelineAggregators = new ArrayList<>(); - for (PipelineAggregatorBuilder factory : this.pipelineAggregatorFactories) { + for (PipelineAggregationBuilder factory : this.pipelineAggregatorFactories) { pipelineAggregators.add(factory.create()); } return pipelineAggregators; @@ -128,7 +128,7 @@ public class AggregatorFactories { for (AggregatorFactory factory : factories) { factory.validate(); } - for (PipelineAggregatorBuilder factory : pipelineAggregatorFactories) { + for (PipelineAggregationBuilder factory : pipelineAggregatorFactories) { factory.validate(parent, factories, pipelineAggregatorFactories); } } @@ -136,7 +136,7 @@ public class AggregatorFactories { public static class Builder extends ToXContentToBytes implements Writeable { private final Set names = new HashSet<>(); private final List aggregationBuilders = new ArrayList<>(); - private final List pipelineAggregatorBuilders = new ArrayList<>(); + private final List pipelineAggregatorBuilders = new ArrayList<>(); private boolean skipResolveOrder; /** @@ -155,7 +155,7 @@ public class AggregatorFactories { } int pipelineFactoriesSize = in.readVInt(); for (int i = 0; i < pipelineFactoriesSize; i++) { - addPipelineAggregator(in.readNamedWriteable(PipelineAggregatorBuilder.class)); + addPipelineAggregator(in.readNamedWriteable(PipelineAggregationBuilder.class)); } } @@ -166,7 +166,7 @@ public class AggregatorFactories { out.writeNamedWriteable(factory); } out.writeVInt(this.pipelineAggregatorBuilders.size()); - for (PipelineAggregatorBuilder factory : pipelineAggregatorBuilders) { + for (PipelineAggregationBuilder factory : pipelineAggregatorBuilders) { out.writeNamedWriteable(factory); } } @@ -183,7 +183,7 @@ public class AggregatorFactories { return this; } - public Builder addPipelineAggregator(PipelineAggregatorBuilder pipelineAggregatorFactory) { + public Builder addPipelineAggregator(PipelineAggregationBuilder pipelineAggregatorFactory) { this.pipelineAggregatorBuilders.add(pipelineAggregatorFactory); return this; } @@ -200,7 +200,7 @@ public class AggregatorFactories { if (aggregationBuilders.isEmpty() && pipelineAggregatorBuilders.isEmpty()) { return EMPTY; } - List orderedpipelineAggregators = null; + List orderedpipelineAggregators = null; if (skipResolveOrder) { orderedpipelineAggregators = new ArrayList<>(pipelineAggregatorBuilders); } else { @@ -213,21 +213,21 @@ public class AggregatorFactories { return new AggregatorFactories(parent, aggFactories, orderedpipelineAggregators); } - private List resolvePipelineAggregatorOrder( - List pipelineAggregatorBuilders, List aggBuilders) { - Map pipelineAggregatorBuildersMap = new HashMap<>(); - for (PipelineAggregatorBuilder builder : pipelineAggregatorBuilders) { + private List resolvePipelineAggregatorOrder( + List pipelineAggregatorBuilders, List aggBuilders) { + Map pipelineAggregatorBuildersMap = new HashMap<>(); + for (PipelineAggregationBuilder builder : pipelineAggregatorBuilders) { pipelineAggregatorBuildersMap.put(builder.getName(), builder); } Map aggBuildersMap = new HashMap<>(); for (AggregationBuilder aggBuilder : aggBuilders) { aggBuildersMap.put(aggBuilder.name, aggBuilder); } - List orderedPipelineAggregatorrs = new LinkedList<>(); - List unmarkedBuilders = new ArrayList(pipelineAggregatorBuilders); - Set temporarilyMarked = new HashSet(); + List orderedPipelineAggregatorrs = new LinkedList<>(); + List unmarkedBuilders = new ArrayList(pipelineAggregatorBuilders); + Set temporarilyMarked = new HashSet(); while (!unmarkedBuilders.isEmpty()) { - PipelineAggregatorBuilder builder = unmarkedBuilders.get(0); + PipelineAggregationBuilder builder = unmarkedBuilders.get(0); resolvePipelineAggregatorOrder(aggBuildersMap, pipelineAggregatorBuildersMap, orderedPipelineAggregatorrs, unmarkedBuilders, temporarilyMarked, builder); } @@ -235,9 +235,9 @@ public class AggregatorFactories { } private void resolvePipelineAggregatorOrder(Map aggBuildersMap, - Map pipelineAggregatorBuildersMap, - List orderedPipelineAggregators, List unmarkedBuilders, - Set temporarilyMarked, PipelineAggregatorBuilder builder) { + Map pipelineAggregatorBuildersMap, + List orderedPipelineAggregators, List unmarkedBuilders, + Set temporarilyMarked, PipelineAggregationBuilder builder) { if (temporarilyMarked.contains(builder)) { throw new IllegalArgumentException("Cyclical dependency found with pipeline aggregator [" + builder.getName() + "]"); } else if (unmarkedBuilders.contains(builder)) { @@ -269,8 +269,8 @@ public class AggregatorFactories { } // Check the pipeline sub-aggregator factories if (!foundSubBuilder && (i == bucketsPathElements.size() - 1)) { - List subPipelineBuilders = aggBuilder.factoriesBuilder.pipelineAggregatorBuilders; - for (PipelineAggregatorBuilder subFactory : subPipelineBuilders) { + List subPipelineBuilders = aggBuilder.factoriesBuilder.pipelineAggregatorBuilders; + for (PipelineAggregationBuilder subFactory : subPipelineBuilders) { if (aggName.equals(subFactory.getName())) { foundSubBuilder = true; break; @@ -285,7 +285,7 @@ public class AggregatorFactories { } continue; } else { - PipelineAggregatorBuilder matchingBuilder = pipelineAggregatorBuildersMap.get(firstAggName); + PipelineAggregationBuilder matchingBuilder = pipelineAggregatorBuildersMap.get(firstAggName); if (matchingBuilder != null) { resolvePipelineAggregatorOrder(aggBuildersMap, pipelineAggregatorBuildersMap, orderedPipelineAggregators, unmarkedBuilders, temporarilyMarked, matchingBuilder); @@ -304,7 +304,7 @@ public class AggregatorFactories { return this.aggregationBuilders.toArray(new AggregationBuilder[this.aggregationBuilders.size()]); } - List getPipelineAggregatorFactories() { + List getPipelineAggregatorFactories() { return this.pipelineAggregatorBuilders; } @@ -321,7 +321,7 @@ public class AggregatorFactories { } } if (pipelineAggregatorBuilders != null) { - for (PipelineAggregatorBuilder subAgg : pipelineAggregatorBuilders) { + for (PipelineAggregationBuilder subAgg : pipelineAggregatorBuilders) { subAgg.toXContent(builder, params); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorParsers.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorParsers.java index 178c1666b18..df64d440dc0 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorParsers.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorParsers.java @@ -104,7 +104,7 @@ public class AggregatorParsers { } AggregationBuilder aggFactory = null; - PipelineAggregatorBuilder pipelineAggregatorFactory = null; + PipelineAggregationBuilder pipelineAggregatorFactory = null; AggregatorFactories.Builder subFactories = null; Map metaData = null; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/PipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/PipelineAggregationBuilder.java similarity index 86% rename from core/src/main/java/org/elasticsearch/search/aggregations/PipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/PipelineAggregationBuilder.java index 1931ec232d5..f9462325471 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/PipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/PipelineAggregationBuilder.java @@ -31,7 +31,7 @@ import java.util.Map; * A factory that knows how to create an {@link PipelineAggregator} of a * specific type. */ -public abstract class PipelineAggregatorBuilder extends ToXContentToBytes +public abstract class PipelineAggregationBuilder extends ToXContentToBytes implements NamedWriteable { protected final String name; @@ -43,7 +43,7 @@ public abstract class PipelineAggregatorBuilder extends ToXContentToBytes * @param name * The aggregation name */ - protected PipelineAggregatorBuilder(String name, String[] bucketsPaths) { + protected PipelineAggregationBuilder(String name, String[] bucketsPaths) { if (name == null) { throw new IllegalArgumentException("[name] must not be null: [" + name + "]"); } @@ -69,7 +69,7 @@ public abstract class PipelineAggregatorBuilder extends ToXContentToBytes * configured) */ protected abstract void validate(AggregatorFactory parent, AggregatorFactory[] factories, - List pipelineAggregatorFactories); + List pipelineAggregatorFactories); /** * Creates the pipeline aggregator @@ -78,7 +78,7 @@ public abstract class PipelineAggregatorBuilder extends ToXContentToBytes */ protected abstract PipelineAggregator create() throws IOException; - /** Associate metadata with this {@link PipelineAggregatorBuilder}. */ - public abstract PipelineAggregatorBuilder setMetaData(Map metaData); + /** Associate metadata with this {@link PipelineAggregationBuilder}. */ + public abstract PipelineAggregationBuilder setMetaData(Map metaData); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/AbstractPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/AbstractPipelineAggregationBuilder.java similarity index 86% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/AbstractPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/AbstractPipelineAggregationBuilder.java index fc308b1bcdd..4fb2ed91401 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/AbstractPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/AbstractPipelineAggregationBuilder.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import java.io.IOException; import java.util.Arrays; @@ -32,10 +32,10 @@ import java.util.Map; import java.util.Objects; /** - * Base implementation of a {@link PipelineAggregatorBuilder}. + * Base implementation of a {@link PipelineAggregationBuilder}. */ -public abstract class AbstractPipelineAggregatorBuilder> - extends PipelineAggregatorBuilder { +public abstract class AbstractPipelineAggregationBuilder> + extends PipelineAggregationBuilder { /** * Field shared by many parsers. @@ -45,7 +45,7 @@ public abstract class AbstractPipelineAggregatorBuilder metaData; - protected AbstractPipelineAggregatorBuilder(String name, String type, String[] bucketsPaths) { + protected AbstractPipelineAggregationBuilder(String name, String type, String[] bucketsPaths) { super(name, bucketsPaths); if (type == null) { throw new IllegalArgumentException("[type] must not be null: [" + name + "]"); @@ -56,7 +56,7 @@ public abstract class AbstractPipelineAggregatorBuilder parent, AggregatorFactory[] factories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { doValidate(parent, factories, pipelineAggregatorFactories); } @@ -99,7 +99,7 @@ public abstract class AbstractPipelineAggregatorBuilder parent, AggregatorFactory[] factories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { } @SuppressWarnings("unchecked") @@ -134,7 +134,7 @@ public abstract class AbstractPipelineAggregatorBuildertrue if the {@link AbstractPipelineAggregatorBuilder} + * @return true if the {@link AbstractPipelineAggregationBuilder} * overrides the XContent rendering of the bucketPath option. */ protected boolean overrideBucketsPath() { @@ -157,7 +157,7 @@ public abstract class AbstractPipelineAggregatorBuilder other = (AbstractPipelineAggregatorBuilder) obj; + AbstractPipelineAggregationBuilder other = (AbstractPipelineAggregationBuilder) obj; if (!Objects.equals(name, other.name)) return false; if (!Objects.equals(type, other.type)) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java index ea0973dd1a2..7e46105346d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java @@ -156,7 +156,7 @@ public class BucketHelpers { try { Object propertyValue = bucket.getProperty(agg.getName(), aggPathAsList); if (propertyValue == null) { - throw new AggregationExecutionException(AbstractPipelineAggregatorBuilder.BUCKETS_PATH_FIELD.getPreferredName() + throw new AggregationExecutionException(AbstractPipelineAggregationBuilder.BUCKETS_PATH_FIELD.getPreferredName() + " must reference either a number value or a single value numeric metric aggregation"); } else { double value; @@ -165,7 +165,7 @@ public class BucketHelpers { } else if (propertyValue instanceof InternalNumericMetricsAggregation.SingleValue) { value = ((InternalNumericMetricsAggregation.SingleValue) propertyValue).value(); } else { - throw new AggregationExecutionException(AbstractPipelineAggregatorBuilder.BUCKETS_PATH_FIELD.getPreferredName() + throw new AggregationExecutionException(AbstractPipelineAggregationBuilder.BUCKETS_PATH_FIELD.getPreferredName() + " must reference either a number value or a single value numeric metric aggregation, got: " + propertyValue.getClass().getCanonicalName()); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregator.java index 4b0dea560a8..8f7ea955e91 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregator.java @@ -28,7 +28,7 @@ import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext; import org.elasticsearch.search.aggregations.InternalAggregation.Type; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import java.io.IOException; import java.util.Map; @@ -36,7 +36,7 @@ import java.util.Map; public abstract class PipelineAggregator implements Streamable { /** - * Parse the {@link PipelineAggregatorBuilder} from a {@link QueryParseContext}. + * Parse the {@link PipelineAggregationBuilder} from a {@link QueryParseContext}. */ @FunctionalInterface public static interface Parser { @@ -56,7 +56,7 @@ public abstract class PipelineAggregator implements Streamable { * @throws java.io.IOException * When parsing fails */ - PipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) + PipelineAggregationBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilders.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilders.java index 9d97fd6af8f..3dc33188495 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilders.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilders.java @@ -20,19 +20,19 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.script.Script; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregationBuilder; import java.util.Map; @@ -41,70 +41,70 @@ public final class PipelineAggregatorBuilders { private PipelineAggregatorBuilders() { } - public static final DerivativePipelineAggregatorBuilder derivative(String name, String bucketsPath) { - return new DerivativePipelineAggregatorBuilder(name, bucketsPath); + public static final DerivativePipelineAggregationBuilder derivative(String name, String bucketsPath) { + return new DerivativePipelineAggregationBuilder(name, bucketsPath); } - public static final MaxBucketPipelineAggregatorBuilder maxBucket(String name, String bucketsPath) { - return new MaxBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final MaxBucketPipelineAggregationBuilder maxBucket(String name, String bucketsPath) { + return new MaxBucketPipelineAggregationBuilder(name, bucketsPath); } - public static final MinBucketPipelineAggregatorBuilder minBucket(String name, String bucketsPath) { - return new MinBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final MinBucketPipelineAggregationBuilder minBucket(String name, String bucketsPath) { + return new MinBucketPipelineAggregationBuilder(name, bucketsPath); } - public static final AvgBucketPipelineAggregatorBuilder avgBucket(String name, String bucketsPath) { - return new AvgBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final AvgBucketPipelineAggregationBuilder avgBucket(String name, String bucketsPath) { + return new AvgBucketPipelineAggregationBuilder(name, bucketsPath); } - public static final SumBucketPipelineAggregatorBuilder sumBucket(String name, String bucketsPath) { - return new SumBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final SumBucketPipelineAggregationBuilder sumBucket(String name, String bucketsPath) { + return new SumBucketPipelineAggregationBuilder(name, bucketsPath); } - public static final StatsBucketPipelineAggregatorBuilder statsBucket(String name, String bucketsPath) { - return new StatsBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final StatsBucketPipelineAggregationBuilder statsBucket(String name, String bucketsPath) { + return new StatsBucketPipelineAggregationBuilder(name, bucketsPath); } - public static final ExtendedStatsBucketPipelineAggregatorBuilder extendedStatsBucket(String name, + public static final ExtendedStatsBucketPipelineAggregationBuilder extendedStatsBucket(String name, String bucketsPath) { - return new ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPath); + return new ExtendedStatsBucketPipelineAggregationBuilder(name, bucketsPath); } - public static final PercentilesBucketPipelineAggregatorBuilder percentilesBucket(String name, + public static final PercentilesBucketPipelineAggregationBuilder percentilesBucket(String name, String bucketsPath) { - return new PercentilesBucketPipelineAggregatorBuilder(name, bucketsPath); + return new PercentilesBucketPipelineAggregationBuilder(name, bucketsPath); } - public static final MovAvgPipelineAggregatorBuilder movingAvg(String name, String bucketsPath) { - return new MovAvgPipelineAggregatorBuilder(name, bucketsPath); + public static final MovAvgPipelineAggregationBuilder movingAvg(String name, String bucketsPath) { + return new MovAvgPipelineAggregationBuilder(name, bucketsPath); } - public static final BucketScriptPipelineAggregatorBuilder bucketScript(String name, + public static final BucketScriptPipelineAggregationBuilder bucketScript(String name, Map bucketsPathsMap, Script script) { - return new BucketScriptPipelineAggregatorBuilder(name, bucketsPathsMap, script); + return new BucketScriptPipelineAggregationBuilder(name, bucketsPathsMap, script); } - public static final BucketScriptPipelineAggregatorBuilder bucketScript(String name, Script script, + public static final BucketScriptPipelineAggregationBuilder bucketScript(String name, Script script, String... bucketsPaths) { - return new BucketScriptPipelineAggregatorBuilder(name, script, bucketsPaths); + return new BucketScriptPipelineAggregationBuilder(name, script, bucketsPaths); } - public static final BucketSelectorPipelineAggregatorBuilder bucketSelector(String name, + public static final BucketSelectorPipelineAggregationBuilder bucketSelector(String name, Map bucketsPathsMap, Script script) { - return new BucketSelectorPipelineAggregatorBuilder(name, bucketsPathsMap, script); + return new BucketSelectorPipelineAggregationBuilder(name, bucketsPathsMap, script); } - public static final BucketSelectorPipelineAggregatorBuilder bucketSelector(String name, Script script, + public static final BucketSelectorPipelineAggregationBuilder bucketSelector(String name, Script script, String... bucketsPaths) { - return new BucketSelectorPipelineAggregatorBuilder(name, script, bucketsPaths); + return new BucketSelectorPipelineAggregationBuilder(name, script, bucketsPaths); } - public static final CumulativeSumPipelineAggregatorBuilder cumulativeSum(String name, + public static final CumulativeSumPipelineAggregationBuilder cumulativeSum(String name, String bucketsPath) { - return new CumulativeSumPipelineAggregatorBuilder(name, bucketsPath); + return new CumulativeSumPipelineAggregationBuilder(name, bucketsPath); } - public static final SerialDiffPipelineAggregatorBuilder diff(String name, String bucketsPath) { - return new SerialDiffPipelineAggregatorBuilder(name, bucketsPath); + public static final SerialDiffPipelineAggregationBuilder diff(String name, String bucketsPath) { + return new SerialDiffPipelineAggregationBuilder(name, bucketsPath); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java index 8eddd83b7e2..9dee002ca29 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java @@ -44,7 +44,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser { } @Override - public final BucketMetricsPipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) + public final BucketMetricsPipelineAggregationBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException { XContentParser parser = context.parser(); XContentParser.Token token; @@ -88,7 +88,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser { "Missing required field [" + BUCKETS_PATH.getPreferredName() + "] for aggregation [" + pipelineAggregatorName + "]"); } - BucketMetricsPipelineAggregatorBuilder factory = buildFactory(pipelineAggregatorName, bucketsPaths[0], params); + BucketMetricsPipelineAggregationBuilder factory = buildFactory(pipelineAggregatorName, bucketsPaths[0], params); if (format != null) { factory.format(format); } @@ -101,7 +101,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser { return factory; } - protected abstract BucketMetricsPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPaths, + protected abstract BucketMetricsPipelineAggregationBuilder buildFactory(String pipelineAggregatorName, String bucketsPaths, Map params); protected boolean token(XContentParser parser, QueryParseContext context, String field, diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsPipelineAggregationBuilder.java similarity index 86% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsPipelineAggregationBuilder.java index 4945fd3a2e5..be34236d044 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsPipelineAggregationBuilder.java @@ -24,9 +24,9 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import java.io.IOException; @@ -34,20 +34,20 @@ import java.util.List; import java.util.Map; import java.util.Objects; -public abstract class BucketMetricsPipelineAggregatorBuilder> - extends AbstractPipelineAggregatorBuilder { +public abstract class BucketMetricsPipelineAggregationBuilder> + extends AbstractPipelineAggregationBuilder { private String format = null; private GapPolicy gapPolicy = GapPolicy.SKIP; - protected BucketMetricsPipelineAggregatorBuilder(String name, String type, String[] bucketsPaths) { + protected BucketMetricsPipelineAggregationBuilder(String name, String type, String[] bucketsPaths) { super(name, type, bucketsPaths); } /** * Read from a stream. */ - protected BucketMetricsPipelineAggregatorBuilder(StreamInput in, String type) throws IOException { + protected BucketMetricsPipelineAggregationBuilder(StreamInput in, String type) throws IOException { super(in, type); format = in.readOptionalString(); gapPolicy = GapPolicy.readFrom(in); @@ -107,7 +107,7 @@ public abstract class BucketMetricsPipelineAggregatorBuilder parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -138,12 +138,12 @@ public abstract class BucketMetricsPipelineAggregatorBuilder other = (BucketMetricsPipelineAggregatorBuilder) obj; + BucketMetricsPipelineAggregationBuilder other = (BucketMetricsPipelineAggregationBuilder) obj; return Objects.equals(format, other.format) && Objects.equals(gapPolicy, other.gapPolicy) && innerEquals(other); } - protected abstract boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other); + protected abstract boolean innerEquals(BucketMetricsPipelineAggregationBuilder other); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregationBuilder.java similarity index 78% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregationBuilder.java index 509b45868b1..d7d7a1e0c57 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregationBuilder.java @@ -24,27 +24,27 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregationBuilder; import java.io.IOException; import java.util.List; import java.util.Map; -public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { +public class AvgBucketPipelineAggregationBuilder extends BucketMetricsPipelineAggregationBuilder { public static final String NAME = AvgBucketPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); - public AvgBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + public AvgBucketPipelineAggregationBuilder(String name, String bucketsPath) { super(name, AvgBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public AvgBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + public AvgBucketPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, NAME); } @@ -60,7 +60,7 @@ public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -74,9 +74,9 @@ public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { @Override - protected AvgBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected AvgBucketPipelineAggregationBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map params) { - return new AvgBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new AvgBucketPipelineAggregationBuilder(pipelineAggregatorName, bucketsPath); } }; @@ -86,7 +86,7 @@ public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg } @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + protected boolean innerEquals(BucketMetricsPipelineAggregationBuilder other) { return true; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregationBuilder.java similarity index 78% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregationBuilder.java index 2800a63661d..0c4fc632b95 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregationBuilder.java @@ -24,27 +24,27 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregationBuilder; import java.io.IOException; import java.util.List; import java.util.Map; -public class MaxBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { +public class MaxBucketPipelineAggregationBuilder extends BucketMetricsPipelineAggregationBuilder { public static final String NAME = MaxBucketPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); - public MaxBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + public MaxBucketPipelineAggregationBuilder(String name, String bucketsPath) { super(name, MaxBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public MaxBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + public MaxBucketPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, NAME); } @@ -60,7 +60,7 @@ public class MaxBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -74,9 +74,9 @@ public class MaxBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { @Override - protected MaxBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected MaxBucketPipelineAggregationBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map params) { - return new MaxBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new MaxBucketPipelineAggregationBuilder(pipelineAggregatorName, bucketsPath); } }; @@ -86,7 +86,7 @@ public class MaxBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg } @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + protected boolean innerEquals(BucketMetricsPipelineAggregationBuilder other) { return true; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregationBuilder.java similarity index 78% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregationBuilder.java index ee7ae9838cc..d20dbe9f7fc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregationBuilder.java @@ -24,27 +24,27 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregationBuilder; import java.io.IOException; import java.util.List; import java.util.Map; -public class MinBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { +public class MinBucketPipelineAggregationBuilder extends BucketMetricsPipelineAggregationBuilder { public static final String NAME = MinBucketPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_FIELD_NAME = new ParseField(NAME); - public MinBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + public MinBucketPipelineAggregationBuilder(String name, String bucketsPath) { super(name, MinBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public MinBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + public MinBucketPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, NAME); } @@ -60,7 +60,7 @@ public class MinBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -74,9 +74,9 @@ public class MinBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { @Override - protected MinBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected MinBucketPipelineAggregationBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map params) { - return new MinBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new MinBucketPipelineAggregationBuilder(pipelineAggregatorName, bucketsPath); } }; @@ -86,7 +86,7 @@ public class MinBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg } @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + protected boolean innerEquals(BucketMetricsPipelineAggregationBuilder other) { return true; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregationBuilder.java similarity index 83% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregationBuilder.java index ddea1a65545..06a1b06dff1 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregationBuilder.java @@ -27,10 +27,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregationBuilder; import java.io.IOException; import java.util.Arrays; @@ -38,8 +38,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; -public class PercentilesBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { +public class PercentilesBucketPipelineAggregationBuilder + extends BucketMetricsPipelineAggregationBuilder { public static final String NAME = PercentilesBucketPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); @@ -47,14 +47,14 @@ public class PercentilesBucketPipelineAggregatorBuilder private double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 }; - public PercentilesBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + public PercentilesBucketPipelineAggregationBuilder(String name, String bucketsPath) { super(name, PercentilesBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public PercentilesBucketPipelineAggregatorBuilder(StreamInput in) + public PercentilesBucketPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, NAME); percents = in.readDoubleArray(); @@ -75,7 +75,7 @@ public class PercentilesBucketPipelineAggregatorBuilder /** * Set the percentages to calculate percentiles for in this aggregation */ - public PercentilesBucketPipelineAggregatorBuilder percents(double[] percents) { + public PercentilesBucketPipelineAggregationBuilder percents(double[] percents) { if (percents == null) { throw new IllegalArgumentException("[percents] must not be null: [" + name + "]"); } @@ -96,7 +96,7 @@ public class PercentilesBucketPipelineAggregatorBuilder @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -121,11 +121,11 @@ public class PercentilesBucketPipelineAggregatorBuilder public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { @Override - protected PercentilesBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected PercentilesBucketPipelineAggregationBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map params) { - PercentilesBucketPipelineAggregatorBuilder factory = new - PercentilesBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + PercentilesBucketPipelineAggregationBuilder factory = new + PercentilesBucketPipelineAggregationBuilder(pipelineAggregatorName, bucketsPath); double[] percents = (double[]) params.get(PERCENTS_FIELD.getPreferredName()); if (percents != null) { @@ -157,8 +157,8 @@ public class PercentilesBucketPipelineAggregatorBuilder } @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder obj) { - PercentilesBucketPipelineAggregatorBuilder other = (PercentilesBucketPipelineAggregatorBuilder) obj; + protected boolean innerEquals(BucketMetricsPipelineAggregationBuilder obj) { + PercentilesBucketPipelineAggregationBuilder other = (PercentilesBucketPipelineAggregationBuilder) obj; return Objects.deepEquals(percents, other.percents); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregationBuilder.java similarity index 79% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregationBuilder.java index a3a37bfe9d6..d3418e897ef 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregationBuilder.java @@ -24,28 +24,28 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregationBuilder; import java.io.IOException; import java.util.List; import java.util.Map; -public class StatsBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { +public class StatsBucketPipelineAggregationBuilder extends BucketMetricsPipelineAggregationBuilder { public static final String NAME = StatsBucketPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); - public StatsBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + public StatsBucketPipelineAggregationBuilder(String name, String bucketsPath) { super(name, StatsBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public StatsBucketPipelineAggregatorBuilder(StreamInput in) + public StatsBucketPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, StatsBucketPipelineAggregator.TYPE.name()); } @@ -62,7 +62,7 @@ public class StatsBucketPipelineAggregatorBuilder extends BucketMetricsPipelineA @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -76,9 +76,9 @@ public class StatsBucketPipelineAggregatorBuilder extends BucketMetricsPipelineA public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { @Override - protected StatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected StatsBucketPipelineAggregationBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map params) { - return new StatsBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new StatsBucketPipelineAggregationBuilder(pipelineAggregatorName, bucketsPath); } }; @@ -88,7 +88,7 @@ public class StatsBucketPipelineAggregatorBuilder extends BucketMetricsPipelineA } @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + protected boolean innerEquals(BucketMetricsPipelineAggregationBuilder other) { return true; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java index 5ab1a6afae0..b7fa49267dc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java @@ -31,10 +31,10 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser { static final ParseField SIGMA = new ParseField("sigma"); @Override - protected ExtendedStatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected ExtendedStatsBucketPipelineAggregationBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map params) { - ExtendedStatsBucketPipelineAggregatorBuilder factory = - new ExtendedStatsBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + ExtendedStatsBucketPipelineAggregationBuilder factory = + new ExtendedStatsBucketPipelineAggregationBuilder(pipelineAggregatorName, bucketsPath); Double sigma = (Double) params.get(SIGMA.getPreferredName()); if (sigma != null) { factory.sigma(sigma); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregationBuilder.java similarity index 81% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregationBuilder.java index 8b17cf7db18..792b9d1f7f1 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregationBuilder.java @@ -24,31 +24,31 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregationBuilder; import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Objects; -public class ExtendedStatsBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { +public class ExtendedStatsBucketPipelineAggregationBuilder + extends BucketMetricsPipelineAggregationBuilder { public static final String NAME = ExtendedStatsBucketPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); private double sigma = 2.0; - public ExtendedStatsBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + public ExtendedStatsBucketPipelineAggregationBuilder(String name, String bucketsPath) { super(name, ExtendedStatsBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public ExtendedStatsBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + public ExtendedStatsBucketPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, ExtendedStatsBucketPipelineAggregator.TYPE.name()); sigma = in.readDouble(); } @@ -62,7 +62,7 @@ public class ExtendedStatsBucketPipelineAggregatorBuilder * Set the value of sigma to use when calculating the standard deviation * bounds */ - public ExtendedStatsBucketPipelineAggregatorBuilder sigma(double sigma) { + public ExtendedStatsBucketPipelineAggregationBuilder sigma(double sigma) { if (sigma < 0.0) { throw new IllegalArgumentException(ExtendedStatsBucketParser.SIGMA.getPreferredName() + " must be a non-negative double"); } @@ -85,7 +85,7 @@ public class ExtendedStatsBucketPipelineAggregatorBuilder @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -109,8 +109,8 @@ public class ExtendedStatsBucketPipelineAggregatorBuilder } @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder obj) { - ExtendedStatsBucketPipelineAggregatorBuilder other = (ExtendedStatsBucketPipelineAggregatorBuilder) obj; + protected boolean innerEquals(BucketMetricsPipelineAggregationBuilder obj) { + ExtendedStatsBucketPipelineAggregationBuilder other = (ExtendedStatsBucketPipelineAggregationBuilder) obj; return Objects.equals(sigma, other.sigma); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregationBuilder.java similarity index 78% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregationBuilder.java index 72ba158a2b2..cf20eaf6e7d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregationBuilder.java @@ -24,27 +24,27 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregationBuilder; import java.io.IOException; import java.util.List; import java.util.Map; -public class SumBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { +public class SumBucketPipelineAggregationBuilder extends BucketMetricsPipelineAggregationBuilder { public static final String NAME = SumBucketPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); - public SumBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + public SumBucketPipelineAggregationBuilder(String name, String bucketsPath) { super(name, SumBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public SumBucketPipelineAggregatorBuilder(StreamInput in) throws IOException { + public SumBucketPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, NAME); } @@ -60,7 +60,7 @@ public class SumBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -74,9 +74,9 @@ public class SumBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() { @Override - protected SumBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected SumBucketPipelineAggregationBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map params) { - return new SumBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new SumBucketPipelineAggregationBuilder(pipelineAggregatorName, bucketsPath); } }; @@ -86,7 +86,7 @@ public class SumBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg } @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + protected boolean innerEquals(BucketMetricsPipelineAggregationBuilder other) { return true; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregationBuilder.java similarity index 91% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregationBuilder.java index 946c48080db..1e285c24a1f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregationBuilder.java @@ -29,7 +29,7 @@ import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.Script; import org.elasticsearch.script.Script.ScriptField; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; @@ -46,7 +46,7 @@ import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator. import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.GAP_POLICY; -public class BucketScriptPipelineAggregatorBuilder extends AbstractPipelineAggregatorBuilder { +public class BucketScriptPipelineAggregationBuilder extends AbstractPipelineAggregationBuilder { public static final String NAME = BucketScriptPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); @@ -55,21 +55,21 @@ public class BucketScriptPipelineAggregatorBuilder extends AbstractPipelineAggre private String format = null; private GapPolicy gapPolicy = GapPolicy.SKIP; - public BucketScriptPipelineAggregatorBuilder(String name, Map bucketsPathsMap, Script script) { + public BucketScriptPipelineAggregationBuilder(String name, Map bucketsPathsMap, Script script) { super(name, BucketScriptPipelineAggregator.TYPE.name(), new TreeMap<>(bucketsPathsMap).values() .toArray(new String[bucketsPathsMap.size()])); this.bucketsPathsMap = bucketsPathsMap; this.script = script; } - public BucketScriptPipelineAggregatorBuilder(String name, Script script, String... bucketsPaths) { + public BucketScriptPipelineAggregationBuilder(String name, Script script, String... bucketsPaths) { this(name, convertToBucketsPathMap(bucketsPaths), script); } /** * Read from a stream. */ - public BucketScriptPipelineAggregatorBuilder(StreamInput in) throws IOException { + public BucketScriptPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, BucketScriptPipelineAggregator.TYPE.name()); int mapSize = in.readVInt(); bucketsPathsMap = new HashMap(mapSize); @@ -104,7 +104,7 @@ public class BucketScriptPipelineAggregatorBuilder extends AbstractPipelineAggre /** * Sets the format to use on the output of this aggregation. */ - public BucketScriptPipelineAggregatorBuilder format(String format) { + public BucketScriptPipelineAggregationBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); } @@ -130,7 +130,7 @@ public class BucketScriptPipelineAggregatorBuilder extends AbstractPipelineAggre /** * Sets the gap policy to use for this aggregation. */ - public BucketScriptPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + public BucketScriptPipelineAggregationBuilder gapPolicy(GapPolicy gapPolicy) { if (gapPolicy == null) { throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); } @@ -161,7 +161,7 @@ public class BucketScriptPipelineAggregatorBuilder extends AbstractPipelineAggre return builder; } - public static BucketScriptPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException { + public static BucketScriptPipelineAggregationBuilder parse(String reducerName, QueryParseContext context) throws IOException { XContentParser parser = context.parser(); XContentParser.Token token; Script script = null; @@ -230,8 +230,8 @@ public class BucketScriptPipelineAggregatorBuilder extends AbstractPipelineAggre + "] for series_arithmetic aggregation [" + reducerName + "]"); } - BucketScriptPipelineAggregatorBuilder factory = - new BucketScriptPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script); + BucketScriptPipelineAggregationBuilder factory = + new BucketScriptPipelineAggregationBuilder(reducerName, bucketsPathsMap, script); if (format != null) { factory.format(format); } @@ -254,7 +254,7 @@ public class BucketScriptPipelineAggregatorBuilder extends AbstractPipelineAggre @Override protected boolean doEquals(Object obj) { - BucketScriptPipelineAggregatorBuilder other = (BucketScriptPipelineAggregatorBuilder) obj; + BucketScriptPipelineAggregationBuilder other = (BucketScriptPipelineAggregationBuilder) obj; return Objects.equals(bucketsPathsMap, other.bucketsPathsMap) && Objects.equals(script, other.script) && Objects.equals(format, other.format) && Objects.equals(gapPolicy, other.gapPolicy); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java similarity index 90% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java index 8e1b854b350..9054812ed3f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregationBuilder.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.Script; import org.elasticsearch.script.Script.ScriptField; -import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; @@ -44,7 +44,7 @@ import java.util.TreeMap; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.GAP_POLICY; -public class BucketSelectorPipelineAggregatorBuilder extends AbstractPipelineAggregatorBuilder { +public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAggregationBuilder { public static final String NAME = BucketSelectorPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); @@ -52,21 +52,21 @@ public class BucketSelectorPipelineAggregatorBuilder extends AbstractPipelineAgg private Script script; private GapPolicy gapPolicy = GapPolicy.SKIP; - public BucketSelectorPipelineAggregatorBuilder(String name, Map bucketsPathsMap, Script script) { + public BucketSelectorPipelineAggregationBuilder(String name, Map bucketsPathsMap, Script script) { super(name, BucketSelectorPipelineAggregator.TYPE.name(), new TreeMap<>(bucketsPathsMap).values() .toArray(new String[bucketsPathsMap.size()])); this.bucketsPathsMap = bucketsPathsMap; this.script = script; } - public BucketSelectorPipelineAggregatorBuilder(String name, Script script, String... bucketsPaths) { + public BucketSelectorPipelineAggregationBuilder(String name, Script script, String... bucketsPaths) { this(name, convertToBucketsPathMap(bucketsPaths), script); } /** * Read from a stream. */ - public BucketSelectorPipelineAggregatorBuilder(StreamInput in) throws IOException { + public BucketSelectorPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, BucketSelectorPipelineAggregator.TYPE.name()); int mapSize = in.readVInt(); bucketsPathsMap = new HashMap(mapSize); @@ -99,7 +99,7 @@ public class BucketSelectorPipelineAggregatorBuilder extends AbstractPipelineAgg /** * Sets the gap policy to use for this aggregation. */ - public BucketSelectorPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + public BucketSelectorPipelineAggregationBuilder gapPolicy(GapPolicy gapPolicy) { if (gapPolicy == null) { throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); } @@ -127,7 +127,7 @@ public class BucketSelectorPipelineAggregatorBuilder extends AbstractPipelineAgg return builder; } - public static BucketSelectorPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException { + public static BucketSelectorPipelineAggregationBuilder parse(String reducerName, QueryParseContext context) throws IOException { XContentParser parser = context.parser(); XContentParser.Token token; Script script = null; @@ -193,8 +193,8 @@ public class BucketSelectorPipelineAggregatorBuilder extends AbstractPipelineAgg + "] for bucket_selector aggregation [" + reducerName + "]"); } - BucketSelectorPipelineAggregatorBuilder factory = - new BucketSelectorPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script); + BucketSelectorPipelineAggregationBuilder factory = + new BucketSelectorPipelineAggregationBuilder(reducerName, bucketsPathsMap, script); if (gapPolicy != null) { factory.gapPolicy(gapPolicy); } @@ -213,7 +213,7 @@ public class BucketSelectorPipelineAggregatorBuilder extends AbstractPipelineAgg @Override protected boolean doEquals(Object obj) { - BucketSelectorPipelineAggregatorBuilder other = (BucketSelectorPipelineAggregatorBuilder) obj; + BucketSelectorPipelineAggregationBuilder other = (BucketSelectorPipelineAggregationBuilder) obj; return Objects.equals(bucketsPathsMap, other.bucketsPathsMap) && Objects.equals(script, other.script) && Objects.equals(gapPolicy, other.gapPolicy); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregationBuilder.java similarity index 88% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregationBuilder.java index a4b2178d0aa..1927317fc2c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregationBuilder.java @@ -28,9 +28,9 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; -import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; @@ -43,20 +43,20 @@ import java.util.Objects; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT; -public class CumulativeSumPipelineAggregatorBuilder extends AbstractPipelineAggregatorBuilder { +public class CumulativeSumPipelineAggregationBuilder extends AbstractPipelineAggregationBuilder { public static final String NAME = CumulativeSumPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); private String format; - public CumulativeSumPipelineAggregatorBuilder(String name, String bucketsPath) { + public CumulativeSumPipelineAggregationBuilder(String name, String bucketsPath) { super(name, CumulativeSumPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public CumulativeSumPipelineAggregatorBuilder(StreamInput in) throws IOException { + public CumulativeSumPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, CumulativeSumPipelineAggregator.TYPE.name()); format = in.readOptionalString(); } @@ -69,7 +69,7 @@ public class CumulativeSumPipelineAggregatorBuilder extends AbstractPipelineAggr /** * Sets the format to use on the output of this aggregation. */ - public CumulativeSumPipelineAggregatorBuilder format(String format) { + public CumulativeSumPipelineAggregationBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); } @@ -99,7 +99,7 @@ public class CumulativeSumPipelineAggregatorBuilder extends AbstractPipelineAggr @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatorFactories) { + List pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -124,7 +124,7 @@ public class CumulativeSumPipelineAggregatorBuilder extends AbstractPipelineAggr return builder; } - public static CumulativeSumPipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) + public static CumulativeSumPipelineAggregationBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException { XContentParser parser = context.parser(); XContentParser.Token token; @@ -167,8 +167,8 @@ public class CumulativeSumPipelineAggregatorBuilder extends AbstractPipelineAggr + "] for derivative aggregation [" + pipelineAggregatorName + "]"); } - CumulativeSumPipelineAggregatorBuilder factory = - new CumulativeSumPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); + CumulativeSumPipelineAggregationBuilder factory = + new CumulativeSumPipelineAggregationBuilder(pipelineAggregatorName, bucketsPaths[0]); if (format != null) { factory.format(format); } @@ -182,7 +182,7 @@ public class CumulativeSumPipelineAggregatorBuilder extends AbstractPipelineAggr @Override protected boolean doEquals(Object obj) { - CumulativeSumPipelineAggregatorBuilder other = (CumulativeSumPipelineAggregatorBuilder) obj; + CumulativeSumPipelineAggregationBuilder other = (CumulativeSumPipelineAggregationBuilder) obj; return Objects.equals(format, other.format); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregationBuilder.java similarity index 89% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregationBuilder.java index 0aba20e37c4..5ad2f88b198 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregationBuilder.java @@ -30,11 +30,11 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; -import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.joda.time.DateTimeZone; @@ -45,7 +45,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; -public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggregatorBuilder { +public class DerivativePipelineAggregationBuilder extends AbstractPipelineAggregationBuilder { public static final String NAME = DerivativePipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); @@ -57,18 +57,18 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega private GapPolicy gapPolicy = GapPolicy.SKIP; private String units; - public DerivativePipelineAggregatorBuilder(String name, String bucketsPath) { + public DerivativePipelineAggregationBuilder(String name, String bucketsPath) { this(name, new String[] { bucketsPath }); } - private DerivativePipelineAggregatorBuilder(String name, String[] bucketsPaths) { + private DerivativePipelineAggregationBuilder(String name, String[] bucketsPaths) { super(name, DerivativePipelineAggregator.TYPE.name(), bucketsPaths); } /** * Read from a stream. */ - public DerivativePipelineAggregatorBuilder(StreamInput in) throws IOException { + public DerivativePipelineAggregationBuilder(StreamInput in) throws IOException { super(in, DerivativePipelineAggregator.TYPE.name()); format = in.readOptionalString(); if (in.readBoolean()) { @@ -88,7 +88,7 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega out.writeOptionalString(units); } - public DerivativePipelineAggregatorBuilder format(String format) { + public DerivativePipelineAggregationBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); } @@ -100,7 +100,7 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega return format; } - public DerivativePipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + public DerivativePipelineAggregationBuilder gapPolicy(GapPolicy gapPolicy) { if (gapPolicy == null) { throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); } @@ -112,7 +112,7 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega return gapPolicy; } - public DerivativePipelineAggregatorBuilder unit(String units) { + public DerivativePipelineAggregationBuilder unit(String units) { if (units == null) { throw new IllegalArgumentException("[units] must not be null: [" + name + "]"); } @@ -120,7 +120,7 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega return this; } - public DerivativePipelineAggregatorBuilder unit(DateHistogramInterval units) { + public DerivativePipelineAggregationBuilder unit(DateHistogramInterval units) { if (units == null) { throw new IllegalArgumentException("[units] must not be null: [" + name + "]"); } @@ -157,7 +157,7 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatoractories) { + List pipelineAggregatoractories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); @@ -188,7 +188,7 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega return builder; } - public static DerivativePipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException { + public static DerivativePipelineAggregationBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException { XContentParser parser = context.parser(); XContentParser.Token token; String currentFieldName = null; @@ -236,8 +236,8 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega + "] for derivative aggregation [" + pipelineAggregatorName + "]"); } - DerivativePipelineAggregatorBuilder factory = - new DerivativePipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); + DerivativePipelineAggregationBuilder factory = + new DerivativePipelineAggregationBuilder(pipelineAggregatorName, bucketsPaths[0]); if (format != null) { factory.format(format); } @@ -252,7 +252,7 @@ public class DerivativePipelineAggregatorBuilder extends AbstractPipelineAggrega @Override protected boolean doEquals(Object obj) { - DerivativePipelineAggregatorBuilder other = (DerivativePipelineAggregatorBuilder) obj; + DerivativePipelineAggregationBuilder other = (DerivativePipelineAggregationBuilder) obj; if (!Objects.equals(format, other.format)) { return false; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregationBuilder.java similarity index 92% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregationBuilder.java index 2cf8a1bd046..7d71af17b42 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregationBuilder.java @@ -29,9 +29,9 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; -import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel; @@ -49,7 +49,7 @@ import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator. import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.GAP_POLICY; -public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorBuilder { +public class MovAvgPipelineAggregationBuilder extends AbstractPipelineAggregationBuilder { public static final String NAME = MovAvgPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_FIELD_NAME = new ParseField(NAME); @@ -66,14 +66,14 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB private int predict = 0; private Boolean minimize; - public MovAvgPipelineAggregatorBuilder(String name, String bucketsPath) { + public MovAvgPipelineAggregationBuilder(String name, String bucketsPath) { super(name, MovAvgPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public MovAvgPipelineAggregatorBuilder(StreamInput in) throws IOException { + public MovAvgPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, MovAvgPipelineAggregator.TYPE.name()); format = in.readOptionalString(); gapPolicy = GapPolicy.readFrom(in); @@ -96,7 +96,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB /** * Sets the format to use on the output of this aggregation. */ - public MovAvgPipelineAggregatorBuilder format(String format) { + public MovAvgPipelineAggregationBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); } @@ -114,7 +114,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB /** * Sets the GapPolicy to use on the output of this aggregation. */ - public MovAvgPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + public MovAvgPipelineAggregationBuilder gapPolicy(GapPolicy gapPolicy) { if (gapPolicy == null) { throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); } @@ -145,7 +145,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB * @param window * Size of window */ - public MovAvgPipelineAggregatorBuilder window(int window) { + public MovAvgPipelineAggregationBuilder window(int window) { if (window <= 0) { throw new IllegalArgumentException("[window] must be a positive integer: [" + name + "]"); } @@ -169,7 +169,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB * @param model * A MovAvgModel which has been prepopulated with settings */ - public MovAvgPipelineAggregatorBuilder modelBuilder(MovAvgModelBuilder model) { + public MovAvgPipelineAggregationBuilder modelBuilder(MovAvgModelBuilder model) { if (model == null) { throw new IllegalArgumentException("[model] must not be null: [" + name + "]"); } @@ -184,7 +184,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB * @param model * A MovAvgModel which has been prepopulated with settings */ - public MovAvgPipelineAggregatorBuilder model(MovAvgModel model) { + public MovAvgPipelineAggregationBuilder model(MovAvgModel model) { if (model == null) { throw new IllegalArgumentException("[model] must not be null: [" + name + "]"); } @@ -209,7 +209,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB * @param predict * Number of predictions to make */ - public MovAvgPipelineAggregatorBuilder predict(int predict) { + public MovAvgPipelineAggregationBuilder predict(int predict) { if (predict <= 0) { throw new IllegalArgumentException("predict must be greater than 0. Found [" + predict + "] in [" + name + "]"); } @@ -234,7 +234,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB * @param minimize * If the model should be fit to the underlying data */ - public MovAvgPipelineAggregatorBuilder minimize(boolean minimize) { + public MovAvgPipelineAggregationBuilder minimize(boolean minimize) { this.minimize = minimize; return this; } @@ -257,7 +257,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB @Override public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List pipelineAggregatoractories) { + List pipelineAggregatoractories) { if (minimize != null && minimize && !model.canBeMinimized()) { // If the user asks to minimize, but this model doesn't support // it, throw exception @@ -296,7 +296,8 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB return builder; } - public static MovAvgPipelineAggregatorBuilder parse(ParseFieldRegistry movingAverageMdelParserRegistry, + public static MovAvgPipelineAggregationBuilder parse( + ParseFieldRegistry movingAverageMdelParserRegistry, String pipelineAggregatorName, QueryParseContext context) throws IOException { XContentParser parser = context.parser(); XContentParser.Token token; @@ -381,8 +382,8 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB + "] for movingAvg aggregation [" + pipelineAggregatorName + "]"); } - MovAvgPipelineAggregatorBuilder factory = - new MovAvgPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); + MovAvgPipelineAggregationBuilder factory = + new MovAvgPipelineAggregationBuilder(pipelineAggregatorName, bucketsPaths[0]); if (format != null) { factory.format(format); } @@ -419,7 +420,7 @@ public class MovAvgPipelineAggregatorBuilder extends AbstractPipelineAggregatorB @Override protected boolean doEquals(Object obj) { - MovAvgPipelineAggregatorBuilder other = (MovAvgPipelineAggregatorBuilder) obj; + MovAvgPipelineAggregationBuilder other = (MovAvgPipelineAggregationBuilder) obj; return Objects.equals(format, other.format) && Objects.equals(gapPolicy, other.gapPolicy) && Objects.equals(window, other.window) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/EwmaModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/EwmaModel.java index 3248096488f..418930d2465 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/EwmaModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/EwmaModel.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder; import java.io.IOException; import java.text.ParseException; @@ -120,8 +120,8 @@ public class EwmaModel extends MovAvgModel { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); - builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.startObject(MovAvgPipelineAggregationBuilder.SETTINGS.getPreferredName()); builder.field("alpha", alpha); builder.endObject(); return builder; @@ -174,8 +174,8 @@ public class EwmaModel extends MovAvgModel { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); - builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.startObject(MovAvgPipelineAggregationBuilder.SETTINGS.getPreferredName()); builder.field("alpha", alpha); builder.endObject(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltLinearModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltLinearModel.java index 23eb1fea036..3ebfeb2ce26 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltLinearModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltLinearModel.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder; import java.io.IOException; import java.text.ParseException; @@ -183,8 +183,8 @@ public class HoltLinearModel extends MovAvgModel { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); - builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.startObject(MovAvgPipelineAggregationBuilder.SETTINGS.getPreferredName()); builder.field("alpha", alpha); builder.field("beta", beta); builder.endObject(); @@ -255,8 +255,8 @@ public class HoltLinearModel extends MovAvgModel { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); - builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.startObject(MovAvgPipelineAggregationBuilder.SETTINGS.getPreferredName()); builder.field("alpha", alpha); builder.field("beta", beta); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltWintersModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltWintersModel.java index 43a0be951cc..9249a4c7116 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltWintersModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/HoltWintersModel.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregationExecutionException; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder; import java.io.IOException; import java.text.ParseException; @@ -366,8 +366,8 @@ public class HoltWintersModel extends MovAvgModel { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); - builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.startObject(MovAvgPipelineAggregationBuilder.SETTINGS.getPreferredName()); builder.field("alpha", alpha); builder.field("beta", beta); builder.field("gamma", gamma); @@ -495,8 +495,8 @@ public class HoltWintersModel extends MovAvgModel { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); - builder.startObject(MovAvgPipelineAggregatorBuilder.SETTINGS.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.startObject(MovAvgPipelineAggregationBuilder.SETTINGS.getPreferredName()); builder.field("alpha", alpha); builder.field("beta", beta); builder.field("gamma", gamma); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/LinearModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/LinearModel.java index 6ce24338917..01ca557ef32 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/LinearModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/LinearModel.java @@ -26,7 +26,7 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder; import java.io.IOException; import java.text.ParseException; @@ -102,7 +102,7 @@ public class LinearModel extends MovAvgModel { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); return builder; } @@ -118,7 +118,7 @@ public class LinearModel extends MovAvgModel { public static class LinearModelBuilder implements MovAvgModelBuilder { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); return builder; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java index 4e9e2112947..7a6c72b00dc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder; import java.io.IOException; import java.text.ParseException; @@ -95,7 +95,7 @@ public class SimpleModel extends MovAvgModel { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME); return builder; } @@ -111,7 +111,7 @@ public class SimpleModel extends MovAvgModel { public static class SimpleModelBuilder implements MovAvgModelBuilder { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); + builder.field(MovAvgPipelineAggregationBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName()); return builder; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregationBuilder.java similarity index 90% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregationBuilder.java index 5f9096542ea..d671e43045b 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregationBuilder.java @@ -27,7 +27,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; @@ -40,7 +40,7 @@ import java.util.Objects; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT; -public class SerialDiffPipelineAggregatorBuilder extends AbstractPipelineAggregatorBuilder { +public class SerialDiffPipelineAggregationBuilder extends AbstractPipelineAggregationBuilder { public static final String NAME = SerialDiffPipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); @@ -51,14 +51,14 @@ public class SerialDiffPipelineAggregatorBuilder extends AbstractPipelineAggrega private GapPolicy gapPolicy = GapPolicy.SKIP; private int lag = 1; - public SerialDiffPipelineAggregatorBuilder(String name, String bucketsPath) { + public SerialDiffPipelineAggregationBuilder(String name, String bucketsPath) { super(name, SerialDiffPipelineAggregator.TYPE.name(), new String[] { bucketsPath }); } /** * Read from a stream. */ - public SerialDiffPipelineAggregatorBuilder(StreamInput in) throws IOException { + public SerialDiffPipelineAggregationBuilder(StreamInput in) throws IOException { super(in, SerialDiffPipelineAggregator.TYPE.name()); format = in.readOptionalString(); gapPolicy = GapPolicy.readFrom(in); @@ -75,7 +75,7 @@ public class SerialDiffPipelineAggregatorBuilder extends AbstractPipelineAggrega /** * Sets the lag to use when calculating the serial difference. */ - public SerialDiffPipelineAggregatorBuilder lag(int lag) { + public SerialDiffPipelineAggregationBuilder lag(int lag) { if (lag <= 0) { throw new IllegalArgumentException("[lag] must be a positive integer: [" + name + "]"); } @@ -93,7 +93,7 @@ public class SerialDiffPipelineAggregatorBuilder extends AbstractPipelineAggrega /** * Sets the format to use on the output of this aggregation. */ - public SerialDiffPipelineAggregatorBuilder format(String format) { + public SerialDiffPipelineAggregationBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); } @@ -111,7 +111,7 @@ public class SerialDiffPipelineAggregatorBuilder extends AbstractPipelineAggrega /** * Sets the GapPolicy to use on the output of this aggregation. */ - public SerialDiffPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + public SerialDiffPipelineAggregationBuilder gapPolicy(GapPolicy gapPolicy) { if (gapPolicy == null) { throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); } @@ -149,7 +149,7 @@ public class SerialDiffPipelineAggregatorBuilder extends AbstractPipelineAggrega return builder; } - public static SerialDiffPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException { + public static SerialDiffPipelineAggregationBuilder parse(String reducerName, QueryParseContext context) throws IOException { XContentParser parser = context.parser(); XContentParser.Token token; String currentFieldName = null; @@ -208,8 +208,8 @@ public class SerialDiffPipelineAggregatorBuilder extends AbstractPipelineAggrega "Missing required field [" + BUCKETS_PATH.getPreferredName() + "] for derivative aggregation [" + reducerName + "]"); } - SerialDiffPipelineAggregatorBuilder factory = - new SerialDiffPipelineAggregatorBuilder(reducerName, bucketsPaths[0]); + SerialDiffPipelineAggregationBuilder factory = + new SerialDiffPipelineAggregationBuilder(reducerName, bucketsPaths[0]); if (lag != null) { factory.lag(lag); } @@ -228,7 +228,7 @@ public class SerialDiffPipelineAggregatorBuilder extends AbstractPipelineAggrega } @Override protected boolean doEquals(Object obj) { - SerialDiffPipelineAggregatorBuilder other = (SerialDiffPipelineAggregatorBuilder) obj; + SerialDiffPipelineAggregationBuilder other = (SerialDiffPipelineAggregationBuilder) obj; return Objects.equals(format, other.format) && Objects.equals(gapPolicy, other.gapPolicy) && Objects.equals(lag, other.lag); diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index b1a5d2d03e6..34b2b536259 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -45,7 +45,7 @@ import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.slice.SliceBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorParsers; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.fetch.source.FetchSourceContext; import org.elasticsearch.search.highlight.HighlightBuilder; import org.elasticsearch.search.internal.SearchContext; @@ -591,7 +591,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ /** * Add an aggregation to perform as part of the search. */ - public SearchSourceBuilder aggregation(PipelineAggregatorBuilder aggregation) { + public SearchSourceBuilder aggregation(PipelineAggregationBuilder aggregation) { if (aggregations == null) { aggregations = AggregatorFactories.builder(); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index 2d3a86fb4be..3e409f3d408 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -52,7 +52,7 @@ import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.SearchModule; -import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.IndexSettingsModule; @@ -70,7 +70,7 @@ import static org.elasticsearch.test.ClusterServiceUtils.createClusterService; import static org.elasticsearch.test.ClusterServiceUtils.setState; import static org.hamcrest.Matchers.equalTo; -public abstract class BasePipelineAggregationTestCase> extends ESTestCase { +public abstract class BasePipelineAggregationTestCase> extends ESTestCase { protected static final String STRING_FIELD_NAME = "mapped_string"; protected static final String INT_FIELD_NAME = "mapped_int"; @@ -198,7 +198,7 @@ public abstract class BasePipelineAggregationTestCase { +public class BucketScriptTests extends BasePipelineAggregationTestCase { @Override - protected BucketScriptPipelineAggregatorBuilder createTestAggregatorFactory() { + protected BucketScriptPipelineAggregationBuilder createTestAggregatorFactory() { String name = randomAsciiOfLengthBetween(3, 20); Map bucketsPaths = new HashMap<>(); int numBucketPaths = randomIntBetween(1, 10); @@ -49,7 +49,7 @@ public class BucketScriptTests extends BasePipelineAggregationTestCase { +public class BucketSelectorTests extends BasePipelineAggregationTestCase { @Override - protected BucketSelectorPipelineAggregatorBuilder createTestAggregatorFactory() { + protected BucketSelectorPipelineAggregationBuilder createTestAggregatorFactory() { String name = randomAsciiOfLengthBetween(3, 20); Map bucketsPaths = new HashMap<>(); int numBucketPaths = randomIntBetween(1, 10); @@ -49,7 +49,7 @@ public class BucketSelectorTests extends BasePipelineAggregationTestCase { +public class CumulativeSumTests extends BasePipelineAggregationTestCase { @Override - protected CumulativeSumPipelineAggregatorBuilder createTestAggregatorFactory() { + protected CumulativeSumPipelineAggregationBuilder createTestAggregatorFactory() { String name = randomAsciiOfLengthBetween(3, 20); String bucketsPath = randomAsciiOfLengthBetween(3, 20); - CumulativeSumPipelineAggregatorBuilder factory = new CumulativeSumPipelineAggregatorBuilder(name, bucketsPath); + CumulativeSumPipelineAggregationBuilder factory = new CumulativeSumPipelineAggregationBuilder(name, bucketsPath); if (randomBoolean()) { factory.format(randomAsciiOfLengthBetween(1, 10)); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeTests.java index 9ceac7b73a2..678bb0b5c4d 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeTests.java @@ -21,15 +21,15 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregationBuilder; -public class DerivativeTests extends BasePipelineAggregationTestCase { +public class DerivativeTests extends BasePipelineAggregationTestCase { @Override - protected DerivativePipelineAggregatorBuilder createTestAggregatorFactory() { + protected DerivativePipelineAggregationBuilder createTestAggregatorFactory() { String name = randomAsciiOfLengthBetween(3, 20); String bucketsPath = randomAsciiOfLengthBetween(3, 20); - DerivativePipelineAggregatorBuilder factory = new DerivativePipelineAggregatorBuilder(name, bucketsPath); + DerivativePipelineAggregationBuilder factory = new DerivativePipelineAggregationBuilder(name, bucketsPath); if (randomBoolean()) { factory.format(randomAsciiOfLengthBetween(1, 10)); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/SerialDifferenceTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/SerialDifferenceTests.java index f7449192d5e..01b31743828 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/SerialDifferenceTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/SerialDifferenceTests.java @@ -21,15 +21,15 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregationBuilder; -public class SerialDifferenceTests extends BasePipelineAggregationTestCase { +public class SerialDifferenceTests extends BasePipelineAggregationTestCase { @Override - protected SerialDiffPipelineAggregatorBuilder createTestAggregatorFactory() { + protected SerialDiffPipelineAggregationBuilder createTestAggregatorFactory() { String name = randomAsciiOfLengthBetween(3, 20); String bucketsPath = randomAsciiOfLengthBetween(3, 20); - SerialDiffPipelineAggregatorBuilder factory = new SerialDiffPipelineAggregatorBuilder(name, bucketsPath); + SerialDiffPipelineAggregationBuilder factory = new SerialDiffPipelineAggregationBuilder(name, bucketsPath); if (randomBoolean()) { factory.format(randomAsciiOfLengthBetween(1, 10)); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AbstractBucketMetricsTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AbstractBucketMetricsTestCase.java index 20c4a614ba2..13ed4027b3a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AbstractBucketMetricsTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AbstractBucketMetricsTestCase.java @@ -22,7 +22,7 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -public abstract class AbstractBucketMetricsTestCase> +public abstract class AbstractBucketMetricsTestCase> extends BasePipelineAggregationTestCase { @Override diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java index 86bf5d92aca..5ae06f671f1 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregationBuilder; -public class AvgBucketTests extends AbstractBucketMetricsTestCase { +public class AvgBucketTests extends AbstractBucketMetricsTestCase { @Override - protected AvgBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { - return new AvgBucketPipelineAggregatorBuilder(name, bucketsPath); + protected AvgBucketPipelineAggregationBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { + return new AvgBucketPipelineAggregationBuilder(name, bucketsPath); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java index 65e8156f71b..e1441b0dc54 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java @@ -23,15 +23,15 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregationBuilder; import static org.hamcrest.Matchers.equalTo; -public class ExtendedStatsBucketTests extends AbstractBucketMetricsTestCase { +public class ExtendedStatsBucketTests extends AbstractBucketMetricsTestCase { @Override - protected ExtendedStatsBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { - ExtendedStatsBucketPipelineAggregatorBuilder factory = new ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPath); + protected ExtendedStatsBucketPipelineAggregationBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { + ExtendedStatsBucketPipelineAggregationBuilder factory = new ExtendedStatsBucketPipelineAggregationBuilder(name, bucketsPath); if (randomBoolean()) { factory.sigma(randomDoubleBetween(0.0, 10.0, false)); } @@ -50,7 +50,7 @@ public class ExtendedStatsBucketTests extends AbstractBucketMetricsTestCase { +public class MaxBucketTests extends AbstractBucketMetricsTestCase { @Override - protected MaxBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { - return new MaxBucketPipelineAggregatorBuilder(name, bucketsPath); + protected MaxBucketPipelineAggregationBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { + return new MaxBucketPipelineAggregationBuilder(name, bucketsPath); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java index 4e0befeb4a5..e577e733b4e 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregationBuilder; -public class MinBucketTests extends AbstractBucketMetricsTestCase { +public class MinBucketTests extends AbstractBucketMetricsTestCase { @Override - protected MinBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { - return new MinBucketPipelineAggregatorBuilder(name, bucketsPath); + protected MinBucketPipelineAggregationBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { + return new MinBucketPipelineAggregationBuilder(name, bucketsPath); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java index 236f122bdd0..e7c478b23f2 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java @@ -23,15 +23,15 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregationBuilder; import static org.hamcrest.Matchers.equalTo; -public class PercentilesBucketTests extends AbstractBucketMetricsTestCase { +public class PercentilesBucketTests extends AbstractBucketMetricsTestCase { @Override - protected PercentilesBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { - PercentilesBucketPipelineAggregatorBuilder factory = new PercentilesBucketPipelineAggregatorBuilder(name, bucketsPath); + protected PercentilesBucketPipelineAggregationBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { + PercentilesBucketPipelineAggregationBuilder factory = new PercentilesBucketPipelineAggregationBuilder(name, bucketsPath); if (randomBoolean()) { int numPercents = randomIntBetween(1, 20); double[] percents = new double[numPercents]; @@ -55,7 +55,7 @@ public class PercentilesBucketTests extends AbstractBucketMetricsTestCase { +public class StatsBucketTests extends AbstractBucketMetricsTestCase { @Override - protected StatsBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, + protected StatsBucketPipelineAggregationBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { - return new StatsBucketPipelineAggregatorBuilder(name, bucketsPath); + return new StatsBucketPipelineAggregationBuilder(name, bucketsPath); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java index 048d26bb612..01ce2277058 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregationBuilder; -public class SumBucketTests extends AbstractBucketMetricsTestCase { +public class SumBucketTests extends AbstractBucketMetricsTestCase { @Override - protected SumBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { - return new SumBucketPipelineAggregatorBuilder(name, bucketsPath); + protected SumBucketPipelineAggregationBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { + return new SumBucketPipelineAggregationBuilder(name, bucketsPath); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java index 8aa294e987f..e34a56c496a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java @@ -24,9 +24,9 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; -import org.elasticsearch.search.aggregations.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder; import org.elasticsearch.search.aggregations.pipeline.movavg.models.EwmaModel; import org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltLinearModel; import org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltWintersModel; @@ -34,13 +34,13 @@ import org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltWintersM import org.elasticsearch.search.aggregations.pipeline.movavg.models.LinearModel; import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel;; -public class MovAvgTests extends BasePipelineAggregationTestCase { +public class MovAvgTests extends BasePipelineAggregationTestCase { @Override - protected MovAvgPipelineAggregatorBuilder createTestAggregatorFactory() { + protected MovAvgPipelineAggregationBuilder createTestAggregatorFactory() { String name = randomAsciiOfLengthBetween(3, 20); String bucketsPath = randomAsciiOfLengthBetween(3, 20); - MovAvgPipelineAggregatorBuilder factory = new MovAvgPipelineAggregatorBuilder(name, bucketsPath); + MovAvgPipelineAggregationBuilder factory = new MovAvgPipelineAggregationBuilder(name, bucketsPath); if (randomBoolean()) { factory.format(randomAsciiOfLengthBetween(1, 10)); } @@ -98,7 +98,7 @@ public class MovAvgTests extends BasePipelineAggregationTestCase aggregationBuilders; - private List pipelineAggregationBuilders; + private List pipelineAggregationBuilders; /** * Sets the document to run the percolate queries against. @@ -140,7 +140,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes { /** * Add an aggregation definition. */ - public PercolateSourceBuilder addAggregation(PipelineAggregatorBuilder aggregationBuilder) { + public PercolateSourceBuilder addAggregation(PipelineAggregationBuilder aggregationBuilder) { if (pipelineAggregationBuilders == null) { pipelineAggregationBuilders = new ArrayList<>(); } @@ -183,7 +183,7 @@ public class PercolateSourceBuilder extends ToXContentToBytes { } } if (pipelineAggregationBuilders != null) { - for (PipelineAggregatorBuilder aggregation : pipelineAggregationBuilders) { + for (PipelineAggregationBuilder aggregation : pipelineAggregationBuilders) { aggregation.toXContent(builder, params); } } From 755721953bf5222ac4784572a1377d28825ef9f5 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 17 Jun 2016 10:43:13 +0200 Subject: [PATCH 29/87] Remove support for sorting terms aggregation by ascending count closes #17614 --- .../bucket/terms/InternalOrder.java | 19 +--- .../bucket/terms/InternalTerms.java | 2 +- .../aggregations/bucket/terms/Terms.java | 6 +- .../bucket/terms/TermsAggregationBuilder.java | 2 +- .../bucket/terms/TermsParser.java | 20 +++- .../aggregations/bucket/ShardSizeTermsIT.java | 24 ++--- .../bucket/TermsDocCountErrorIT.java | 93 ------------------- .../aggregations/bucket/TermsTests.java | 2 +- .../bucket/terms-aggregation.asciidoc | 13 ++- .../migrate_5_0/aggregations.asciidoc | 4 + .../messy/tests/DoubleTermsTests.java | 7 +- .../messy/tests/LongTermsTests.java | 7 +- .../messy/tests/MinDocCountTests.java | 48 ++-------- .../messy/tests/StringTermsTests.java | 7 +- .../test/search.aggregation/20_terms.yaml | 15 ++- 15 files changed, 75 insertions(+), 194 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalOrder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalOrder.java index f3f87c09dca..5ebeb6ee7fb 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalOrder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalOrder.java @@ -46,9 +46,8 @@ import java.util.Objects; class InternalOrder extends Terms.Order { private static final byte COUNT_DESC_ID = 1; - private static final byte COUNT_ASC_ID = 2; - private static final byte TERM_DESC_ID = 3; - private static final byte TERM_ASC_ID = 4; + private static final byte TERM_DESC_ID = 2; + private static final byte TERM_ASC_ID = 3; /** * Order by the (higher) count of each term. @@ -60,17 +59,6 @@ class InternalOrder extends Terms.Order { } }); - /** - * Order by the (lower) count of each term. - */ - public static final InternalOrder COUNT_ASC = new InternalOrder(COUNT_ASC_ID, "_count", true, new Comparator() { - - @Override - public int compare(Terms.Bucket o1, Terms.Bucket o2) { - return Long.compare(o1.getDocCount(), o2.getDocCount()); - } - }); - /** * Order by the terms. */ @@ -93,7 +81,7 @@ class InternalOrder extends Terms.Order { } }); - public static boolean isCountDesc(Terms.Order order) { + public static boolean isCountOrder(Terms.Order order) { if (order == COUNT_DESC) { return true; } else if (order instanceof CompoundOrder) { @@ -348,7 +336,6 @@ class InternalOrder extends Terms.Order { byte id = in.readByte(); switch (id) { case COUNT_DESC_ID: return absoluteOrder ? new CompoundOrder(Collections.singletonList((Terms.Order) InternalOrder.COUNT_DESC)) : InternalOrder.COUNT_DESC; - case COUNT_ASC_ID: return absoluteOrder ? new CompoundOrder(Collections.singletonList((Terms.Order) InternalOrder.COUNT_ASC)) : InternalOrder.COUNT_ASC; case TERM_DESC_ID: return InternalOrder.TERM_DESC; case TERM_ASC_ID: return InternalOrder.TERM_ASC; case Aggregation.ID: diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTerms.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTerms.java index fcbd66dced6..5784066f85c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTerms.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTerms.java @@ -192,7 +192,7 @@ public abstract class InternalTerms otherOptions) throws IOException { - if (token == XContentParser.Token.START_OBJECT) { + if (token == Token.VALUE_STRING) { if (parseFieldMatcher.match(currentFieldName, TermsAggregationBuilder.ORDER_FIELD)) { - otherOptions.put(TermsAggregationBuilder.ORDER_FIELD, Collections.singletonList(parseOrderParam(aggregationName, parser))); + if ("_count".equals(parser.text())) { + otherOptions.put(TermsAggregationBuilder.ORDER_FIELD, + Collections.singletonList(new OrderElement(parser.text(), false))); + return true; + } + } + return false; + } else if (token == XContentParser.Token.START_OBJECT) { + if (parseFieldMatcher.match(currentFieldName, TermsAggregationBuilder.ORDER_FIELD)) { + otherOptions.put(TermsAggregationBuilder.ORDER_FIELD, + Collections.singletonList(parseOrderParam(aggregationName, parser))); return true; } } else if (token == XContentParser.Token.START_ARRAY) { @@ -117,6 +127,10 @@ public class TermsParser extends AbstractTermsParser { } else if (token == XContentParser.Token.VALUE_STRING) { String dir = parser.text(); if ("asc".equalsIgnoreCase(dir)) { + if ("_count".equals(orderKey)) { + throw new ParsingException(parser.getTokenLocation(), + "Sort by ascending _count is not supported in [" + aggregationName + "]."); + } orderAsc = true; } else if ("desc".equalsIgnoreCase(dir)) { orderAsc = false; @@ -167,7 +181,7 @@ public class TermsParser extends AbstractTermsParser { return Order.term(asc); } if ("_count".equals(key)) { - return Order.count(asc); + return Order.count(); } return Order.aggregation(key, asc); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTermsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTermsIT.java index ecc16b85f13..82b60289c75 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTermsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTermsIT.java @@ -39,7 +39,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -62,7 +62,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3).shardSize(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -86,7 +86,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -110,7 +110,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type").setRouting(routing1) .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -156,7 +156,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -179,7 +179,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3).shardSize(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -202,7 +202,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -226,7 +226,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type").setRouting(routing1) .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -272,7 +272,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -295,7 +295,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3).shardSize(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -318,7 +318,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -341,7 +341,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type").setRouting(routing1) .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java index 6bbe1dc22b2..00c73b42246 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java @@ -271,37 +271,6 @@ public class TermsDocCountErrorIT extends ESIntegTestCase { assertNoDocCountErrorSingleResponse(size, testResponse); } - public void testStringValueFieldDocCountAsc() throws Exception { - int size = randomIntBetween(1, 20); - int shardSize = randomIntBetween(size, size * 2); - SearchResponse accurateResponse = client().prepareSearch("idx_single_shard").setTypes("type") - .addAggregation(terms("terms") - .executionHint(randomExecutionHint()) - .field(STRING_FIELD_NAME) - .showTermDocCountError(true) - .size(10000).shardSize(10000) - .order(Order.count(true)) - .collectMode(randomFrom(SubAggCollectionMode.values()))) - .execute().actionGet(); - - assertSearchResponse(accurateResponse); - - SearchResponse testResponse = client().prepareSearch("idx_single_shard").setTypes("type") - .addAggregation(terms("terms") - .executionHint(randomExecutionHint()) - .field(STRING_FIELD_NAME) - .showTermDocCountError(true) - .size(size) - .shardSize(shardSize) - .order(Order.count(true)) - .collectMode(randomFrom(SubAggCollectionMode.values()))) - .execute().actionGet(); - - assertSearchResponse(testResponse); - - assertUnboundedDocCountError(size, accurateResponse, testResponse); - } - public void testStringValueFieldTermSortAsc() throws Exception { int size = randomIntBetween(1, 20); int shardSize = randomIntBetween(size, size * 2); @@ -507,37 +476,6 @@ public class TermsDocCountErrorIT extends ESIntegTestCase { assertNoDocCountErrorSingleResponse(size, testResponse); } - public void testLongValueFieldDocCountAsc() throws Exception { - int size = randomIntBetween(1, 20); - int shardSize = randomIntBetween(size, size * 2); - SearchResponse accurateResponse = client().prepareSearch("idx_single_shard").setTypes("type") - .addAggregation(terms("terms") - .executionHint(randomExecutionHint()) - .field(LONG_FIELD_NAME) - .showTermDocCountError(true) - .size(10000).shardSize(10000) - .order(Order.count(true)) - .collectMode(randomFrom(SubAggCollectionMode.values()))) - .execute().actionGet(); - - assertSearchResponse(accurateResponse); - - SearchResponse testResponse = client().prepareSearch("idx_single_shard").setTypes("type") - .addAggregation(terms("terms") - .executionHint(randomExecutionHint()) - .field(LONG_FIELD_NAME) - .showTermDocCountError(true) - .size(size) - .shardSize(shardSize) - .order(Order.count(true)) - .collectMode(randomFrom(SubAggCollectionMode.values()))) - .execute().actionGet(); - - assertSearchResponse(testResponse); - - assertUnboundedDocCountError(size, accurateResponse, testResponse); - } - public void testLongValueFieldTermSortAsc() throws Exception { int size = randomIntBetween(1, 20); int shardSize = randomIntBetween(size, size * 2); @@ -743,37 +681,6 @@ public class TermsDocCountErrorIT extends ESIntegTestCase { assertNoDocCountErrorSingleResponse(size, testResponse); } - public void testDoubleValueFieldDocCountAsc() throws Exception { - int size = randomIntBetween(1, 20); - int shardSize = randomIntBetween(size, size * 2); - SearchResponse accurateResponse = client().prepareSearch("idx_single_shard").setTypes("type") - .addAggregation(terms("terms") - .executionHint(randomExecutionHint()) - .field(DOUBLE_FIELD_NAME) - .showTermDocCountError(true) - .size(10000).shardSize(10000) - .order(Order.count(true)) - .collectMode(randomFrom(SubAggCollectionMode.values()))) - .execute().actionGet(); - - assertSearchResponse(accurateResponse); - - SearchResponse testResponse = client().prepareSearch("idx_single_shard").setTypes("type") - .addAggregation(terms("terms") - .executionHint(randomExecutionHint()) - .field(DOUBLE_FIELD_NAME) - .showTermDocCountError(true) - .size(size) - .shardSize(shardSize) - .order(Order.count(true)) - .collectMode(randomFrom(SubAggCollectionMode.values()))) - .execute().actionGet(); - - assertSearchResponse(testResponse); - - assertUnboundedDocCountError(size, accurateResponse, testResponse); - } - public void testDoubleValueFieldTermSortAsc() throws Exception { int size = randomIntBetween(1, 20); int shardSize = randomIntBetween(size, size * 2); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java index c8a14e82bf4..055258bb4cc 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java @@ -180,7 +180,7 @@ public class TermsTests extends BaseAggregationTestCase orders.add(Terms.Order.term(randomBoolean())); break; case 1: - orders.add(Terms.Order.count(randomBoolean())); + orders.add(Terms.Order.count()); break; case 2: orders.add(Terms.Order.aggregation(randomAsciiOfLengthBetween(3, 20), randomBoolean())); diff --git a/docs/reference/aggregations/bucket/terms-aggregation.asciidoc b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc index 3c1f4ae860a..30e3d649179 100644 --- a/docs/reference/aggregations/bucket/terms-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc @@ -239,9 +239,7 @@ determined and is given a value of -1 to indicate this. ==== Order The order of the buckets can be customized by setting the `order` parameter. By default, the buckets are ordered by -their `doc_count` descending. It is also possible to change this behaviour as follows: - -Ordering the buckets by their `doc_count` in an ascending manner: +their `doc_count` descending: [source,js] -------------------------------------------------- @@ -250,12 +248,15 @@ Ordering the buckets by their `doc_count` in an ascending manner: "genders" : { "terms" : { "field" : "gender", - "order" : { "_count" : "asc" } + "order" : "_count" <1> } } } } -------------------------------------------------- +<1> This is the default if the order is missing. + +It is also possible to change this behaviour as follows: Ordering the buckets alphabetically by their terms in an ascending manner: @@ -312,7 +313,9 @@ Ordering the buckets by multi value metrics sub-aggregation (identified by the a } -------------------------------------------------- -WARNING: Sorting by ascending `_count` or by sub aggregation is discouraged as it increases the +Ordering the buckets by their `doc_count` in an ascending manner is not supported. + +WARNING: Sorting by sub aggregation is discouraged as it increases the <> on document counts. It is fine when a single shard is queried, or when the field that is being aggregated was used as a routing key at index time: in these cases results will be accurate since shards have disjoint diff --git a/docs/reference/migration/migrate_5_0/aggregations.asciidoc b/docs/reference/migration/migrate_5_0/aggregations.asciidoc index d9227e91385..57afd44719b 100644 --- a/docs/reference/migration/migrate_5_0/aggregations.asciidoc +++ b/docs/reference/migration/migrate_5_0/aggregations.asciidoc @@ -26,3 +26,7 @@ for `from` and `to` anymore. `size: 0` is no longer valid for the terms, significant terms and geohash grid aggregations. Instead a size should be explicitly specified with a number greater than zero. + +==== `order: {"count": "asc"}` on Terms + +The ability to sort the terms aggregation by ascending count has been removed. diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/DoubleTermsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/DoubleTermsTests.java index 6ed77fffcc8..5e1dec0402f 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/DoubleTermsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/DoubleTermsTests.java @@ -1048,11 +1048,6 @@ public class DoubleTermsTests extends AbstractTermsTestCase { assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("avg_l", false), Terms.Order.term(true)); } - public void testSingleValuedFieldOrderedByCountAscAndSingleValueSubAggregationAsc() throws Exception { - double[] expectedKeys = new double[] { 6, 7, 3, 4, 5, 1, 2 }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(true), Terms.Order.aggregation("avg_l", true)); - } - public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscSingleValueSubAggregationAsc() throws Exception { double[] expectedKeys = new double[] { 6, 7, 3, 5, 4, 1, 2 }; assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("sum_d", true), Terms.Order.aggregation("avg_l", true)); @@ -1060,7 +1055,7 @@ public class DoubleTermsTests extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByThreeCriteria() throws Exception { double[] expectedKeys = new double[] { 2, 1, 4, 5, 3, 6, 7 }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(false), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); + assertMultiSortResponse(expectedKeys, Terms.Order.count(), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); } public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscAsCompound() throws Exception { diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java index fa049429a3a..efc9833a33d 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java @@ -1025,11 +1025,6 @@ public class LongTermsTests extends AbstractTermsTestCase { assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("avg_l", false), Terms.Order.term(true)); } - public void testSingleValuedFieldOrderedByCountAscAndSingleValueSubAggregationAsc() throws Exception { - long[] expectedKeys = new long[] { 6, 7, 3, 4, 5, 1, 2 }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(true), Terms.Order.aggregation("avg_l", true)); - } - public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscSingleValueSubAggregationAsc() throws Exception { long[] expectedKeys = new long[] { 6, 7, 3, 5, 4, 1, 2 }; assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("sum_d", true), Terms.Order.aggregation("avg_l", true)); @@ -1037,7 +1032,7 @@ public class LongTermsTests extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByThreeCriteria() throws Exception { long[] expectedKeys = new long[] { 2, 1, 4, 5, 3, 6, 7 }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(false), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); + assertMultiSortResponse(expectedKeys, Terms.Order.count(), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); } public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscAsCompound() throws Exception { diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/MinDocCountTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/MinDocCountTests.java index 662d4d2f30c..c24551ed588 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/MinDocCountTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/MinDocCountTests.java @@ -173,36 +173,20 @@ public class MinDocCountTests extends AbstractTermsTestCase { testMinDocCountOnTerms("s", Script.YES, Terms.Order.term(false)); } - public void testStringCountAsc() throws Exception { - testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(true)); - } - - public void testStringScriptCountAsc() throws Exception { - testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(true)); - } - public void testStringCountDesc() throws Exception { - testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(false)); + testMinDocCountOnTerms("s", Script.NO, Terms.Order.count()); } public void testStringScriptCountDesc() throws Exception { - testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(false)); - } - - public void testStringCountAscWithInclude() throws Exception { - testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(true), ".*a.*", true); - } - - public void testStringScriptCountAscWithInclude() throws Exception { - testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(true), ".*a.*", true); + testMinDocCountOnTerms("s", Script.YES, Terms.Order.count()); } public void testStringCountDescWithInclude() throws Exception { - testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(false), ".*a.*", true); + testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(), ".*a.*", true); } public void testStringScriptCountDescWithInclude() throws Exception { - testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(false), ".*a.*", true); + testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(), ".*a.*", true); } public void testLongTermAsc() throws Exception { @@ -221,20 +205,12 @@ public class MinDocCountTests extends AbstractTermsTestCase { testMinDocCountOnTerms("l", Script.YES, Terms.Order.term(false)); } - public void testLongCountAsc() throws Exception { - testMinDocCountOnTerms("l", Script.NO, Terms.Order.count(true)); - } - - public void testLongScriptCountAsc() throws Exception { - testMinDocCountOnTerms("l", Script.YES, Terms.Order.count(true)); - } - public void testLongCountDesc() throws Exception { - testMinDocCountOnTerms("l", Script.NO, Terms.Order.count(false)); + testMinDocCountOnTerms("l", Script.NO, Terms.Order.count()); } public void testLongScriptCountDesc() throws Exception { - testMinDocCountOnTerms("l", Script.YES, Terms.Order.count(false)); + testMinDocCountOnTerms("l", Script.YES, Terms.Order.count()); } public void testDoubleTermAsc() throws Exception { @@ -253,20 +229,12 @@ public class MinDocCountTests extends AbstractTermsTestCase { testMinDocCountOnTerms("d", Script.YES, Terms.Order.term(false)); } - public void testDoubleCountAsc() throws Exception { - testMinDocCountOnTerms("d", Script.NO, Terms.Order.count(true)); - } - - public void testDoubleScriptCountAsc() throws Exception { - testMinDocCountOnTerms("d", Script.YES, Terms.Order.count(true)); - } - public void testDoubleCountDesc() throws Exception { - testMinDocCountOnTerms("d", Script.NO, Terms.Order.count(false)); + testMinDocCountOnTerms("d", Script.NO, Terms.Order.count()); } public void testDoubleScriptCountDesc() throws Exception { - testMinDocCountOnTerms("d", Script.YES, Terms.Order.count(false)); + testMinDocCountOnTerms("d", Script.YES, Terms.Order.count()); } private void testMinDocCountOnTerms(String field, Script script, Terms.Order order) throws Exception { diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java index b098db154da..a5825d23172 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java @@ -1375,11 +1375,6 @@ public class StringTermsTests extends AbstractTermsTestCase { assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("avg_l", false), Terms.Order.term(true)); } - public void testSingleValuedFieldOrderedByCountAscAndSingleValueSubAggregationAsc() throws Exception { - String[] expectedKeys = new String[] { "val6", "val7", "val3", "val4", "val5", "val1", "val2" }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(true), Terms.Order.aggregation("avg_l", true)); - } - public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscSingleValueSubAggregationAsc() throws Exception { String[] expectedKeys = new String[] { "val6", "val7", "val3", "val5", "val4", "val1", "val2" }; assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("sum_d", true), Terms.Order.aggregation("avg_l", true)); @@ -1387,7 +1382,7 @@ public class StringTermsTests extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByThreeCriteria() throws Exception { String[] expectedKeys = new String[] { "val2", "val1", "val4", "val5", "val3", "val6", "val7" }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(false), Terms.Order.aggregation("sum_d", false), + assertMultiSortResponse(expectedKeys, Terms.Order.count(), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yaml index c35e79e6cfe..c079e6b6f7e 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yaml @@ -350,4 +350,17 @@ setup: - match: { aggregations.date_terms.buckets.0.key_as_string: "2014-09-01T00:00:00.000Z" } - - match: { aggregations.date_terms.buckets.0.doc_count: 1 } + - match: { aggregations.date_terms.buckets.0.doc_count: 1 } + +--- +"Terms count order test": + - do: + catch: /Sort by ascending _count is not supported in/ + search: + body: { "size" : 0, "aggs" : { "count_order" : { "terms" : { "field" : "f1", "order": {"_count": "asc"} } } } } + + - do: + search: + body: { "size" : 0, "aggs" : { "count_order" : { "terms" : { "field" : "f1", "order": "_count" } } } } + + From bce1abec48c521a422f6016479343b28f2538c7d Mon Sep 17 00:00:00 2001 From: Mateusz Rzepa Date: Fri, 17 Jun 2016 16:19:04 +0200 Subject: [PATCH 30/87] Update integrations.asciidoc (#18915) --- docs/plugins/integrations.asciidoc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/plugins/integrations.asciidoc b/docs/plugins/integrations.asciidoc index ee3ccef194c..d39d02efeac 100644 --- a/docs/plugins/integrations.asciidoc +++ b/docs/plugins/integrations.asciidoc @@ -187,3 +187,18 @@ releases 2.0 and later do not support rivers. * https://www.wireshark.org/[Wireshark]: Protocol dissection for Zen discovery, HTTP and the binary protocol +* https://www.itemsapi.com/[ItemsAPI]: + Search backend for mobile and web + + +These projects appear to have been abandoned: + +* http://www.github.com/neogenix/daikon[daikon]: + Daikon Elasticsearch CLI + +* https://github.com/fullscale/dangle[dangle]: + A set of AngularJS directives that provide common visualizations for elasticsearch based on + D3. +* https://github.com/OlegKunitsyn/eslogd[eslogd]: + Linux daemon that replicates events to a central Elasticsearch server in realtime +>>>>>>> 02602a3... Update integrations.asciidoc (#18915) From 82fee9f7a714c756534fe32fcdedcae5c42cf8fd Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 17 Jun 2016 17:02:00 +0200 Subject: [PATCH 31/87] Revert change about registering Repository settings Will create another issue to change that. Related to this discussion: https://github.com/elastic/elasticsearch/pull/17784/files/f4cd3bd3480bf6c0a51faf408d8ea9c8a8733a6b#r67291936 --- .../plugin/repository/s3/S3RepositoryPlugin.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java b/plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java index 7922174f40e..26ff53a6e62 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java @@ -129,6 +129,22 @@ public class S3RepositoryPlugin extends Plugin { settingsModule.registerSetting(S3Repository.Repositories.CANNED_ACL_SETTING); settingsModule.registerSetting(S3Repository.Repositories.BASE_PATH_SETTING); settingsModule.registerSetting(S3Repository.Repositories.USE_THROTTLE_RETRIES_SETTING); + + // Register S3 single repository settings + settingsModule.registerSetting(S3Repository.Repository.KEY_SETTING); + settingsModule.registerSetting(S3Repository.Repository.SECRET_SETTING); + settingsModule.registerSetting(S3Repository.Repository.BUCKET_SETTING); + settingsModule.registerSetting(S3Repository.Repository.ENDPOINT_SETTING); + settingsModule.registerSetting(S3Repository.Repository.PROTOCOL_SETTING); + settingsModule.registerSetting(S3Repository.Repository.REGION_SETTING); + settingsModule.registerSetting(S3Repository.Repository.SERVER_SIDE_ENCRYPTION_SETTING); + settingsModule.registerSetting(S3Repository.Repository.BUFFER_SIZE_SETTING); + settingsModule.registerSetting(S3Repository.Repository.MAX_RETRIES_SETTING); + settingsModule.registerSetting(S3Repository.Repository.CHUNK_SIZE_SETTING); + settingsModule.registerSetting(S3Repository.Repository.COMPRESS_SETTING); + settingsModule.registerSetting(S3Repository.Repository.STORAGE_CLASS_SETTING); + settingsModule.registerSetting(S3Repository.Repository.CANNED_ACL_SETTING); + settingsModule.registerSetting(S3Repository.Repository.BASE_PATH_SETTING); } /** From bdb6dcea3ae53e7dea8ce060c46100ed8f25385e Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 17 Jun 2016 17:07:19 +0200 Subject: [PATCH 32/87] Cleanup ClusterService dependencies and detached from Guice (#18941) This change removes some unnecessary dependencies from ClusterService and cleans up ClusterName creation. ClusterService is now not created by guice anymore. --- .../allocation/AllocationBenchmark.java | 3 +- .../resources/checkstyle_suppressions.xml | 3 -- .../health/TransportClusterHealthAction.java | 9 ++-- .../TransportNodesHotThreadsAction.java | 6 +-- .../node/info/TransportNodesInfoAction.java | 7 ++- .../node/liveness/LivenessResponse.java | 2 +- .../liveness/TransportLivenessAction.java | 8 +--- .../node/stats/TransportNodesStatsAction.java | 7 ++- .../cancel/TransportCancelTasksAction.java | 5 +-- .../tasks/list/TransportListTasksAction.java | 5 +-- .../TransportVerifyRepositoryAction.java | 7 +-- .../verify/VerifyRepositoryResponse.java | 2 +- .../status/TransportNodesSnapshotsStatus.java | 9 ++-- .../cluster/state/ClusterStateResponse.java | 2 +- .../state/TransportClusterStateAction.java | 7 +-- .../stats/TransportClusterStatsAction.java | 9 ++-- .../action/main/MainResponse.java | 2 +- .../support/nodes/BaseNodesResponse.java | 2 +- .../support/nodes/TransportNodesAction.java | 6 +-- .../support/tasks/TransportTasksAction.java | 5 +-- .../client/transport/TransportClient.java | 2 - .../TransportClientNodesService.java | 4 +- .../elasticsearch/cluster/ClusterModule.java | 7 +-- .../elasticsearch/cluster/ClusterName.java | 41 +++++------------ .../cluster/ClusterNameModule.java | 40 ----------------- .../elasticsearch/cluster/ClusterState.java | 6 +-- .../cluster/health/ClusterStateHealth.java | 13 ------ .../cluster/routing/OperationRouting.java | 18 ++++---- .../routing/allocation/AllocationService.java | 9 +++- .../allocator/BalancedShardsAllocator.java | 1 - .../decider/AwarenessAllocationDecider.java | 9 ---- .../cluster/service/ClusterService.java | 19 +++++--- .../common/network/NetworkModule.java | 6 +-- .../common/settings/ClusterSettings.java | 2 +- .../discovery/local/LocalDiscovery.java | 4 +- .../discovery/zen/ZenDiscovery.java | 10 ++--- .../zen/fd/MasterFaultDetection.java | 6 +-- .../discovery/zen/fd/NodesFaultDetection.java | 2 +- .../discovery/zen/ping/ZenPing.java | 7 +-- .../zen/ping/unicast/UnicastZenPing.java | 34 ++++++-------- .../org/elasticsearch/env/Environment.java | 5 ++- .../org/elasticsearch/gateway/Gateway.java | 2 +- .../TransportNodesListGatewayMetaState.java | 6 +-- ...ransportNodesListGatewayStartedShards.java | 6 +-- .../indices/store/IndicesStore.java | 4 +- .../TransportNodesListShardStoreMetaData.java | 6 +-- .../java/org/elasticsearch/node/Node.java | 6 +-- .../transport/TransportService.java | 13 ++---- .../health/ClusterHealthResponsesTests.java | 3 +- .../node/tasks/CancellableTasksTests.java | 7 ++- .../node/tasks/TaskManagerTestCase.java | 15 +++---- .../cluster/node/tasks/TestTaskPlugin.java | 10 ++--- .../node/tasks/TransportTasksActionTests.java | 17 ++++--- .../cluster/reroute/ClusterRerouteTests.java | 3 +- .../shrink/TransportShrinkActionTests.java | 3 +- .../bulk/TransportBulkActionTookTests.java | 2 +- .../action/support/AutoCreateIndexTests.java | 2 +- .../TransportBroadcastByNodeActionTests.java | 2 +- .../TransportMasterNodeActionTests.java | 2 +- .../nodes/TransportNodesActionTests.java | 14 +++--- .../BroadcastReplicationTests.java | 2 +- .../TransportReplicationActionTests.java | 2 +- ...ortInstanceSingleOperationActionTests.java | 2 +- .../AbstractTermVectorsTestCase.java | 2 +- .../transport/FailAndRetryMockTransport.java | 4 +- .../TransportClientHeadersTests.java | 7 +-- .../TransportClientNodesServiceTests.java | 7 +-- .../cluster/ClusterModuleTests.java | 20 +++++---- .../cluster/ClusterStateTests.java | 15 ++++--- .../cluster/NodeConnectionsServiceTests.java | 2 +- ...rdFailedClusterStateTaskExecutorTests.java | 2 +- .../action/shard/ShardStateActionTests.java | 2 +- .../health/ClusterStateHealthTests.java | 7 ++- .../MetaDataCreateIndexServiceTests.java | 6 ++- .../DelayedAllocationServiceTests.java | 8 ++-- .../routing/OperationRoutingTests.java | 4 +- .../cluster/routing/PrimaryTermsTests.java | 4 +- .../RoutingBackwardCompatibilityTests.java | 13 ++++-- .../cluster/routing/RoutingTableTests.java | 2 +- .../cluster/routing/UnassignedInfoTests.java | 22 +++++----- .../allocation/ActiveAllocationIdTests.java | 4 +- .../allocation/AddIncrementallyTests.java | 2 +- .../allocation/AllocationCommandsTests.java | 6 +-- .../allocation/AllocationPriorityTests.java | 2 +- .../allocation/AwarenessAllocationTests.java | 22 +++++----- .../allocation/BalanceConfigurationTests.java | 4 +- .../allocation/CatAllocationTestCase.java | 2 +- .../ClusterRebalanceRoutingTests.java | 16 +++---- .../ConcurrentRebalanceRoutingTests.java | 2 +- .../allocation/DeadNodesAllocationTests.java | 6 +-- ...ReplicaAsPrimaryDuringRelocationTests.java | 2 +- .../ExpectedShardSizeAllocationTests.java | 4 +- .../allocation/FailedNodeRoutingTests.java | 4 +- .../allocation/FailedShardsRoutingTests.java | 16 +++---- .../FilterAllocationDeciderTests.java | 4 +- .../allocation/FilterRoutingTests.java | 6 +-- .../routing/allocation/IndexBalanceTests.java | 6 +-- .../MaxRetryAllocationDeciderTests.java | 3 +- .../NodeVersionAllocationDeciderTests.java | 10 ++--- ...alPrimariesToRelocatingPrimariesTests.java | 2 +- .../PreferPrimaryAllocationTests.java | 2 +- .../PrimaryElectionRoutingTests.java | 4 +- ...yNotRelocatedWhileBeingRecoveredTests.java | 2 +- .../RandomAllocationDeciderTests.java | 2 +- .../allocation/RebalanceAfterActiveTests.java | 2 +- .../ReplicaAllocatedAfterPrimaryTests.java | 2 +- .../RoutingNodesIntegrityTests.java | 6 +-- .../allocation/SameShardRoutingTests.java | 3 +- .../allocation/ShardVersioningTests.java | 2 +- .../ShardsLimitAllocationTests.java | 6 +-- .../SingleShardNoReplicasRoutingTests.java | 8 ++-- .../SingleShardOneReplicaRoutingTests.java | 2 +- .../allocation/StartedShardsRoutingTests.java | 3 +- .../TenShardsOneReplicaRoutingTests.java | 2 +- .../allocation/ThrottlingAllocationTests.java | 8 ++-- .../UpdateNumberOfReplicasTests.java | 2 +- .../decider/DiskThresholdDeciderTests.java | 15 ++++--- .../DiskThresholdDeciderUnitTests.java | 8 ++-- .../decider/EnableAllocationTests.java | 10 ++--- .../ClusterSerializationTests.java | 4 +- .../ClusterStateToStringTests.java | 6 ++- .../cluster/service/ClusterServiceTests.java | 11 +++-- .../structure/RoutingIteratorTests.java | 15 ++++--- .../discovery/ZenFaultDetectionTests.java | 20 +++++---- .../discovery/zen/ZenPingTests.java | 4 +- .../zen/ping/unicast/UnicastZenPingIT.java | 44 +++++++++++-------- .../PendingClusterStatesQueueTests.java | 3 +- .../PublishClusterStateActionTests.java | 4 +- .../gateway/GatewayMetaStateTests.java | 4 +- .../gateway/GatewayServiceTests.java | 4 +- .../gateway/PrimaryShardAllocatorTests.java | 10 ++--- .../gateway/ReplicaShardAllocatorTests.java | 4 +- .../elasticsearch/http/HttpServerTests.java | 5 +-- .../mapper/DynamicMappingDisabledTests.java | 2 +- .../indices/cluster/ClusterStateChanges.java | 2 +- ...ClusterStateServiceRandomUpdatesTests.java | 2 +- .../indices/store/IndicesStoreTests.java | 2 +- .../org/elasticsearch/mget/SimpleMgetIT.java | 4 +- .../InternalSettingsPreparerTests.java | 7 --- .../bucket/ShardSizeTestCase.java | 4 +- .../AbstractSimpleTransportTestCase.java | 11 ++--- .../NettySizeHeaderFrameDecoderTests.java | 2 +- .../NettyTransportServiceHandshakeTests.java | 35 ++++++--------- .../transport/TransportModuleTests.java | 4 +- .../local/SimpleLocalTransportTests.java | 4 +- .../netty/NettyScheduledPingTests.java | 6 +-- .../netty/SimpleNettyTransportTests.java | 4 +- .../messy/tests/IndicesRequestTests.java | 4 +- .../reindex/TransportRethrottleAction.java | 4 +- .../discovery/ec2/Ec2DiscoveryTests.java | 2 +- .../discovery/gce/GceDiscoveryTests.java | 2 +- .../MockInternalClusterInfoService.java | 2 +- .../test/ClusterServiceUtils.java | 4 +- .../elasticsearch/test/ESIntegTestCase.java | 5 +-- .../test/ESSingleNodeTestCase.java | 2 - .../org/elasticsearch/test/ExternalNode.java | 1 - .../test/InternalTestCluster.java | 4 +- .../test/transport/MockTransportService.java | 13 +++--- 158 files changed, 497 insertions(+), 592 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/cluster/ClusterNameModule.java diff --git a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java index d5bb0916eca..5e5f35f6040 100644 --- a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java +++ b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java @@ -147,7 +147,8 @@ public class AllocationBenchmark { for (int i = 1; i <= numNodes; i++) { nb.put(Allocators.newNode("node" + i, Collections.singletonMap("tag", "tag_" + (i % numTags)))); } - initialClusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).nodes + initialClusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) + .metaData(metaData).routingTable(routingTable).nodes (nb).build(); } diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index 0a4dbbf3ff9..94494a06542 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -754,7 +754,6 @@ - @@ -784,13 +783,11 @@ - - diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java index 204eab7aaf4..de616c61907 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.ClusterStateUpdateTask; @@ -47,16 +46,14 @@ import org.elasticsearch.transport.TransportService; */ public class TransportClusterHealthAction extends TransportMasterNodeReadAction { - private final ClusterName clusterName; private final GatewayAllocator gatewayAllocator; @Inject public TransportClusterHealthAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ClusterName clusterName, ActionFilters actionFilters, + ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, GatewayAllocator gatewayAllocator) { super(settings, ClusterHealthAction.NAME, false, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, ClusterHealthRequest::new); - this.clusterName = clusterName; this.gatewayAllocator = gatewayAllocator; } @@ -284,14 +281,14 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction< concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); } catch (IndexNotFoundException e) { // one of the specified indices is not there - treat it as RED. - ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState, + ClusterHealthResponse response = new ClusterHealthResponse(clusterState.getClusterName().value(), Strings.EMPTY_ARRAY, clusterState, numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), pendingTaskTimeInQueue); response.setStatus(ClusterHealthStatus.RED); return response; } - return new ClusterHealthResponse(clusterName.value(), concreteIndices, clusterState, numberOfPendingTasks, + return new ClusterHealthResponse(clusterState.getClusterName().value(), concreteIndices, clusterState, numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), pendingTaskTimeInQueue); } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/TransportNodesHotThreadsAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/TransportNodesHotThreadsAction.java index 7198851fd28..73403f40318 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/TransportNodesHotThreadsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/TransportNodesHotThreadsAction.java @@ -47,17 +47,17 @@ public class TransportNodesHotThreadsAction extends TransportNodesAction { @Inject - public TransportNodesHotThreadsAction(Settings settings, ClusterName clusterName, ThreadPool threadPool, + public TransportNodesHotThreadsAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, NodesHotThreadsAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters, + super(settings, NodesHotThreadsAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver, NodesHotThreadsRequest::new, NodeRequest::new, ThreadPool.Names.GENERIC, NodeHotThreads.class); } @Override protected NodesHotThreadsResponse newResponse(NodesHotThreadsRequest request, List responses, List failures) { - return new NodesHotThreadsResponse(clusterName, responses, failures); + return new NodesHotThreadsResponse(clusterService.getClusterName(), responses, failures); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java index f68e2d65903..8b6cc8210fa 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.nodes.BaseNodeRequest; import org.elasticsearch.action.support.nodes.TransportNodesAction; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; @@ -48,11 +47,11 @@ public class TransportNodesInfoAction extends TransportNodesAction responses, List failures) { - return new NodesInfoResponse(clusterName, responses, failures); + return new NodesInfoResponse(clusterService.getClusterName(), responses, failures); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/liveness/LivenessResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/liveness/LivenessResponse.java index b0a53190bf0..a9ba36ffeff 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/liveness/LivenessResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/liveness/LivenessResponse.java @@ -47,7 +47,7 @@ public final class LivenessResponse extends ActionResponse { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - clusterName = ClusterName.readClusterName(in); + clusterName = new ClusterName(in); node = in.readOptionalWriteable(DiscoveryNode::new); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/liveness/TransportLivenessAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/liveness/TransportLivenessAction.java index a437fc5ee49..09c608ac842 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/liveness/TransportLivenessAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/liveness/TransportLivenessAction.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.admin.cluster.node.liveness; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.threadpool.ThreadPool; @@ -30,20 +29,17 @@ import org.elasticsearch.transport.TransportService; public final class TransportLivenessAction implements TransportRequestHandler { private final ClusterService clusterService; - private final ClusterName clusterName; public static final String NAME = "cluster:monitor/nodes/liveness"; @Inject - public TransportLivenessAction(ClusterName clusterName, - ClusterService clusterService, TransportService transportService) { + public TransportLivenessAction(ClusterService clusterService, TransportService transportService) { this.clusterService = clusterService; - this.clusterName = clusterName; transportService.registerRequestHandler(NAME, LivenessRequest::new, ThreadPool.Names.SAME, false, false /*can not trip circuit breaker*/, this); } @Override public void messageReceived(LivenessRequest request, TransportChannel channel) throws Exception { - channel.sendResponse(new LivenessResponse(clusterName, clusterService.localNode())); + channel.sendResponse(new LivenessResponse(clusterService.getClusterName(), clusterService.localNode())); } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java index d61e3f1acce..5863e54d08f 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.nodes.BaseNodeRequest; import org.elasticsearch.action.support.nodes.TransportNodesAction; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; @@ -48,18 +47,18 @@ public class TransportNodesStatsAction extends TransportNodesAction responses, List failures) { - return new NodesStatsResponse(clusterName, responses, failures); + return new NodesStatsResponse(clusterService.getClusterName(), responses, failures); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/cancel/TransportCancelTasksAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/cancel/TransportCancelTasksAction.java index bc69228055a..6d5936db67a 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/cancel/TransportCancelTasksAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/cancel/TransportCancelTasksAction.java @@ -24,7 +24,6 @@ import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.TaskOperationFailure; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.tasks.TransportTasksAction; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -63,10 +62,10 @@ public class TransportCancelTasksAction extends TransportTasksAction responses, List failures) { - return new NodesSnapshotStatus(clusterName, responses, failures); + return new NodesSnapshotStatus(clusterService.getClusterName(), responses, failures); } @Override @@ -158,9 +158,6 @@ public class TransportNodesSnapshotsStatus extends TransportNodesAction { - NodesSnapshotStatus() { - } - public NodesSnapshotStatus(ClusterName clusterName, List nodes, List failures) { super(clusterName, nodes, failures); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java index e9aa9b723fa..2a2f4707f69 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java @@ -54,7 +54,7 @@ public class ClusterStateResponse extends ActionResponse { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - clusterName = ClusterName.readClusterName(in); + clusterName = new ClusterName(in); clusterState = ClusterState.Builder.readFrom(in, null); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java index 77a42108280..ea1c1507448 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java @@ -23,7 +23,6 @@ import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -42,13 +41,11 @@ import org.elasticsearch.transport.TransportService; */ public class TransportClusterStateAction extends TransportMasterNodeReadAction { - private final ClusterName clusterName; @Inject public TransportClusterStateAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - ClusterName clusterName, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { + ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, ClusterStateAction.NAME, false, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, ClusterStateRequest::new); - this.clusterName = clusterName; } @Override @@ -127,7 +124,7 @@ public class TransportClusterStateAction extends TransportMasterNodeReadAction responses, List failures) { - return new ClusterStatsResponse(System.currentTimeMillis(), clusterName, clusterService.state().metaData().clusterUUID(), - responses, failures); + return new ClusterStatsResponse(System.currentTimeMillis(), clusterService.getClusterName(), + clusterService.state().metaData().clusterUUID(), responses, failures); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/main/MainResponse.java b/core/src/main/java/org/elasticsearch/action/main/MainResponse.java index b9d094c7e9e..2403c3ee49c 100644 --- a/core/src/main/java/org/elasticsearch/action/main/MainResponse.java +++ b/core/src/main/java/org/elasticsearch/action/main/MainResponse.java @@ -84,7 +84,7 @@ public class MainResponse extends ActionResponse implements ToXContent { super.readFrom(in); nodeName = in.readString(); version = Version.readVersion(in); - clusterName = ClusterName.readClusterName(in); + clusterName = new ClusterName(in); build = Build.readBuild(in); available = in.readBoolean(); } diff --git a/core/src/main/java/org/elasticsearch/action/support/nodes/BaseNodesResponse.java b/core/src/main/java/org/elasticsearch/action/support/nodes/BaseNodesResponse.java index a49864154db..462f0b07bd6 100644 --- a/core/src/main/java/org/elasticsearch/action/support/nodes/BaseNodesResponse.java +++ b/core/src/main/java/org/elasticsearch/action/support/nodes/BaseNodesResponse.java @@ -106,7 +106,7 @@ public abstract class BaseNodesResponse @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - clusterName = ClusterName.readClusterName(in); + clusterName = new ClusterName(in); nodes = readNodesFrom(in); failures = in.readList(FailedNodeException::new); } diff --git a/core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java b/core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java index 2b72ef8b31b..5d39d378b21 100644 --- a/core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java @@ -24,13 +24,11 @@ import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.NoSuchNodeException; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -59,21 +57,19 @@ public abstract class TransportNodesAction extends HandledTransportAction { - protected final ClusterName clusterName; protected final ClusterService clusterService; protected final TransportService transportService; protected final Class nodeResponseClass; final String transportNodeAction; - protected TransportNodesAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool, + protected TransportNodesAction(Settings settings, String actionName, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Supplier request, Supplier nodeRequest, String nodeExecutor, Class nodeResponseClass) { super(settings, actionName, threadPool, transportService, actionFilters, indexNameExpressionResolver, request); - this.clusterName = Objects.requireNonNull(clusterName); this.clusterService = Objects.requireNonNull(clusterService); this.transportService = Objects.requireNonNull(transportService); this.nodeResponseClass = Objects.requireNonNull(nodeResponseClass); diff --git a/core/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java b/core/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java index e3070832417..f28b70b88ed 100644 --- a/core/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java @@ -26,7 +26,6 @@ import org.elasticsearch.action.NoSuchNodeException; import org.elasticsearch.action.TaskOperationFailure; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -67,7 +66,6 @@ public abstract class TransportTasksAction< TaskResponse extends Writeable > extends HandledTransportAction { - protected final ClusterName clusterName; protected final ClusterService clusterService; protected final TransportService transportService; protected final Supplier requestSupplier; @@ -75,13 +73,12 @@ public abstract class TransportTasksAction< protected final String transportNodeAction; - protected TransportTasksAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool, + protected TransportTasksAction(Settings settings, String actionName, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Supplier requestSupplier, Supplier responseSupplier, String nodeExecutor) { super(settings, actionName, threadPool, transportService, actionFilters, indexNameExpressionResolver, requestSupplier); - this.clusterName = clusterName; this.clusterService = clusterService; this.transportService = transportService; this.transportNodeAction = actionName + "[n]"; diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 56f541631ab..089fb41a321 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -28,7 +28,6 @@ import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.support.AbstractClient; import org.elasticsearch.client.transport.support.TransportProxyClient; -import org.elasticsearch.cluster.ClusterNameModule; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Injector; @@ -137,7 +136,6 @@ public class TransportClient extends AbstractClient { } modules.add(new PluginsModule(pluginsService)); modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry)); - modules.add(new ClusterNameModule(settings)); modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool)); modules.add(new SearchModule(settings, namedWriteableRegistry) { @Override diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java index 71c5895669c..cfa8adc28a7 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java @@ -111,10 +111,10 @@ public class TransportClientNodesService extends AbstractComponent { Setting.boolSetting("client.transport.sniff", false, Property.NodeScope); @Inject - public TransportClientNodesService(Settings settings, ClusterName clusterName, TransportService transportService, + public TransportClientNodesService(Settings settings,TransportService transportService, ThreadPool threadPool, Version version) { super(settings); - this.clusterName = clusterName; + this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); this.transportService = transportService; this.threadPool = threadPool; this.minCompatibilityVersion = version.minimumCompatibilityVersion(); diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/core/src/main/java/org/elasticsearch/cluster/ClusterModule.java index c90dbcd3c54..cc11b58727d 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/core/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -100,17 +100,19 @@ public class ClusterModule extends AbstractModule { private final ExtensionPoint.SelectedType shardsAllocators = new ExtensionPoint.SelectedType<>("shards_allocator", ShardsAllocator.class); private final ExtensionPoint.ClassSet allocationDeciders = new ExtensionPoint.ClassSet<>("allocation_decider", AllocationDecider.class, AllocationDeciders.class); private final ExtensionPoint.ClassSet indexTemplateFilters = new ExtensionPoint.ClassSet<>("index_template_filter", IndexTemplateFilter.class); + private final ClusterService clusterService; // pkg private so tests can mock Class clusterInfoServiceImpl = InternalClusterInfoService.class; - public ClusterModule(Settings settings) { + public ClusterModule(Settings settings, ClusterService clusterService) { this.settings = settings; for (Class decider : ClusterModule.DEFAULT_ALLOCATION_DECIDERS) { registerAllocationDecider(decider); } registerShardsAllocator(ClusterModule.BALANCED_ALLOCATOR, BalancedShardsAllocator.class); registerShardsAllocator(ClusterModule.EVEN_SHARD_COUNT_ALLOCATOR, BalancedShardsAllocator.class); + this.clusterService = clusterService; } public void registerAllocationDecider(Class allocationDecider) { @@ -140,9 +142,8 @@ public class ClusterModule extends AbstractModule { bind(GatewayAllocator.class).asEagerSingleton(); bind(AllocationService.class).asEagerSingleton(); bind(DiscoveryNodeService.class).asEagerSingleton(); - bind(ClusterService.class).asEagerSingleton(); + bind(ClusterService.class).toInstance(clusterService); bind(NodeConnectionsService.class).asEagerSingleton(); - bind(OperationRouting.class).asEagerSingleton(); bind(MetaDataCreateIndexService.class).asEagerSingleton(); bind(MetaDataDeleteIndexService.class).asEagerSingleton(); bind(MetaDataIndexStateService.class).asEagerSingleton(); diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterName.java b/core/src/main/java/org/elasticsearch/cluster/ClusterName.java index 09c64065dbd..36676300954 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterName.java +++ b/core/src/main/java/org/elasticsearch/cluster/ClusterName.java @@ -21,37 +21,29 @@ package org.elasticsearch.cluster; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.settings.Setting; -import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import java.io.IOException; +import java.util.Objects; -/** - * - */ -public class ClusterName implements Streamable { +public class ClusterName implements Writeable { - public static final Setting CLUSTER_NAME_SETTING = new Setting<>("cluster.name", "elasticsearch", (s) -> { + public static final Setting CLUSTER_NAME_SETTING = new Setting<>("cluster.name", "elasticsearch", (s) -> { if (s.isEmpty()) { throw new IllegalArgumentException("[cluster.name] must not be empty"); } - return s; - }, Property.NodeScope); + return new ClusterName(s); + }, Setting.Property.NodeScope); + public static final ClusterName DEFAULT = CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY); - public static final ClusterName DEFAULT = new ClusterName(CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY).intern()); + private final String value; - private String value; - - public static ClusterName clusterNameFromSettings(Settings settings) { - return new ClusterName(CLUSTER_NAME_SETTING.get(settings)); + public ClusterName(StreamInput input) throws IOException { + this(input.readString()); } - - private ClusterName() { - } - public ClusterName(String value) { this.value = value.intern(); } @@ -60,17 +52,6 @@ public class ClusterName implements Streamable { return this.value; } - public static ClusterName readClusterName(StreamInput in) throws IOException { - ClusterName clusterName = new ClusterName(); - clusterName.readFrom(in); - return clusterName; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - value = in.readString().intern(); - } - @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(value); @@ -90,7 +71,7 @@ public class ClusterName implements Streamable { @Override public int hashCode() { - return value != null ? value.hashCode() : 0; + return Objects.hash(value); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterNameModule.java b/core/src/main/java/org/elasticsearch/cluster/ClusterNameModule.java deleted file mode 100644 index 55513c3c9be..00000000000 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterNameModule.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.cluster; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.settings.Settings; - -/** - * - */ -public class ClusterNameModule extends AbstractModule { - - private final Settings settings; - - public ClusterNameModule(Settings settings) { - this.settings = settings; - } - - @Override - protected void configure() { - bind(ClusterName.class).toInstance(ClusterName.clusterNameFromSettings(settings)); - } -} diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java index 17c0b646760..7674874c0ba 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -90,7 +90,7 @@ import java.util.Set; */ public class ClusterState implements ToXContent, Diffable { - public static final ClusterState PROTO = builder(ClusterName.DEFAULT).build(); + public static final ClusterState PROTO = builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).build(); public static enum ClusterStateStatus { UNKNOWN((byte) 0), @@ -734,7 +734,7 @@ public class ClusterState implements ToXContent, Diffable { } public ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws IOException { - ClusterName clusterName = ClusterName.readClusterName(in); + ClusterName clusterName = new ClusterName(in); Builder builder = new Builder(clusterName); builder.version = in.readLong(); builder.uuid = in.readString(); @@ -805,7 +805,7 @@ public class ClusterState implements ToXContent, Diffable { } public ClusterStateDiff(StreamInput in, ClusterState proto) throws IOException { - clusterName = ClusterName.readClusterName(in); + clusterName = new ClusterName(in); fromUuid = in.readString(); toUuid = in.readString(); toVersion = in.readLong(); diff --git a/core/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java b/core/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java index 5d267fa142d..8aeb110c370 100644 --- a/core/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java +++ b/core/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java @@ -18,12 +18,9 @@ */ package org.elasticsearch.cluster.health; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.IndexRoutingTable; -import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -50,16 +47,6 @@ public final class ClusterStateHealth implements Iterable, W private final ClusterHealthStatus status; private final Map indices = new HashMap<>(); - /** - * Creates a new ClusterStateHealth instance based on cluster meta data and its routing table as a convenience. - * - * @param clusterMetaData Current cluster meta data. Must not be null. - * @param routingTables Current routing table. Must not be null. - */ - public ClusterStateHealth(final MetaData clusterMetaData, final RoutingTable routingTables) { - this(ClusterState.builder(ClusterName.DEFAULT).metaData(clusterMetaData).routingTable(routingTables).build()); - } - /** * Creates a new ClusterStateHealth instance considering the current cluster state and all indices in the cluster. * diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 129650de991..19189e0c286 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -26,7 +26,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationD import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.shard.ShardId; @@ -42,12 +42,17 @@ import java.util.stream.Collectors; public class OperationRouting extends AbstractComponent { - private final AwarenessAllocationDecider awarenessAllocationDecider; + private String[] awarenessAttributes; - @Inject - public OperationRouting(Settings settings, AwarenessAllocationDecider awarenessAllocationDecider) { + public OperationRouting(Settings settings, ClusterSettings clusterSettings) { super(settings); - this.awarenessAllocationDecider = awarenessAllocationDecider; + this.awarenessAttributes = AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.get(settings); + clusterSettings.addSettingsUpdateConsumer(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING, + this::setAwarenessAttributes); + } + + private void setAwarenessAttributes(String[] awarenessAttributes) { + this.awarenessAttributes = awarenessAttributes; } public ShardIterator indexShards(ClusterState clusterState, String index, String id, @Nullable String routing) { @@ -111,7 +116,6 @@ public class OperationRouting extends AbstractComponent { private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable indexShard, String localNodeId, DiscoveryNodes nodes, @Nullable String preference) { if (preference == null || preference.isEmpty()) { - String[] awarenessAttributes = awarenessAllocationDecider.awarenessAttributes(); if (awarenessAttributes.length == 0) { return indexShard.activeInitializingShardsRandomIt(); } else { @@ -143,7 +147,6 @@ public class OperationRouting extends AbstractComponent { } // no more preference if (index == -1 || index == preference.length() - 1) { - String[] awarenessAttributes = awarenessAllocationDecider.awarenessAttributes(); if (awarenessAttributes.length == 0) { return indexShard.activeInitializingShardsRandomIt(); } else { @@ -186,7 +189,6 @@ public class OperationRouting extends AbstractComponent { } } // if not, then use it as the index - String[] awarenessAttributes = awarenessAllocationDecider.awarenessAttributes(); if (awarenessAttributes.length == 0) { return indexShard.activeInitializingShardsIt(Murmur3HashFunction.hash(preference)); } else { diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java index 55954f0f1e4..7a91c694399 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.routing.allocation; import org.elasticsearch.cluster.ClusterInfoService; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.health.ClusterStateHealth; @@ -68,6 +69,7 @@ public class AllocationService extends AbstractComponent { private final GatewayAllocator gatewayAllocator; private final ShardsAllocator shardsAllocator; private final ClusterInfoService clusterInfoService; + private final ClusterName clusterName; @Inject public AllocationService(Settings settings, AllocationDeciders allocationDeciders, GatewayAllocator gatewayAllocator, @@ -77,6 +79,7 @@ public class AllocationService extends AbstractComponent { this.gatewayAllocator = gatewayAllocator; this.shardsAllocator = shardsAllocator; this.clusterInfoService = clusterInfoService; + clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); } /** @@ -118,8 +121,10 @@ public class AllocationService extends AbstractComponent { MetaData newMetaData = updateMetaDataWithRoutingTable(oldMetaData, oldRoutingTable, newRoutingTable); assert newRoutingTable.validate(newMetaData); // validates the routing table is coherent with the cluster state metadata logClusterHealthStateChange( - new ClusterStateHealth(allocation.metaData(), allocation.routingTable()), - new ClusterStateHealth(newMetaData, newRoutingTable), + new ClusterStateHealth(ClusterState.builder(clusterName). + metaData(allocation.metaData()).routingTable(allocation.routingTable()).build()), + new ClusterStateHealth(ClusterState.builder(clusterName). + metaData(newMetaData).routingTable(newRoutingTable).build()), reason ); return new RoutingAllocation.Result(true, newRoutingTable, newMetaData, explanations); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java index 1f69b771fdb..046947d64eb 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java @@ -203,7 +203,6 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards final float weightIndex = node.numShards(index) + numAdditionalShards - balancer.avgShardsPerNode(index); return theta0 * weightShard + theta1 * weightIndex; } - } /** diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java index ed7ab3bd68e..32eaa8ddec6 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java @@ -126,15 +126,6 @@ public class AwarenessAllocationDecider extends AllocationDecider { this.forcedAwarenessAttributes = forcedAwarenessAttributes; } - /** - * Get the attributes defined by this instance - * - * @return attributes defined by this instance - */ - public String[] awarenessAttributes() { - return this.awarenessAttributes; - } - private void setAwarenessAttributes(String[] awarenessAttributes) { this.awarenessAttributes = awarenessAttributes; } diff --git a/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java b/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java index 13bbccc863a..7573f260a54 100644 --- a/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java +++ b/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java @@ -44,7 +44,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.ClusterSettings; @@ -97,6 +96,7 @@ public class ClusterService extends AbstractLifecycleComponent { public static final String UPDATE_THREAD_NAME = "clusterService#updateTask"; private final ThreadPool threadPool; + private final ClusterName clusterName; private BiConsumer clusterStatePublisher; @@ -130,14 +130,13 @@ public class ClusterService extends AbstractLifecycleComponent { private NodeConnectionsService nodeConnectionsService; - @Inject - public ClusterService(Settings settings, OperationRouting operationRouting, - ClusterSettings clusterSettings, ThreadPool threadPool, ClusterName clusterName) { + public ClusterService(Settings settings, + ClusterSettings clusterSettings, ThreadPool threadPool) { super(settings); - this.operationRouting = operationRouting; + this.operationRouting = new OperationRouting(settings, clusterSettings); this.threadPool = threadPool; this.clusterSettings = clusterSettings; - + this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); // will be replaced on doStart. this.clusterState = ClusterState.builder(clusterName).build(); @@ -490,6 +489,10 @@ public class ClusterService extends AbstractLifecycleComponent { return true; } + public ClusterName getClusterName() { + return clusterName; + } + static abstract class SourcePrioritizedRunnable extends PrioritizedRunnable { protected final String source; @@ -1039,4 +1042,8 @@ public class ClusterService extends AbstractLifecycleComponent { public ClusterSettings getClusterSettings() { return clusterSettings; } + + public Settings getSettings() { + return settings; + } } diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java index 1484ad64018..9de4d557599 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java @@ -168,11 +168,11 @@ public class NetworkModule extends AbstractModule { public static final String LOCAL_TRANSPORT = "local"; public static final String NETTY_TRANSPORT = "netty"; - public static final Setting HTTP_TYPE_SETTING = Setting.simpleString("http.type", Property.NodeScope); + public static final Setting HTTP_TYPE_SETTING = Setting.simpleString(HTTP_TYPE_KEY, Property.NodeScope); public static final Setting HTTP_ENABLED = Setting.boolSetting("http.enabled", true, Property.NodeScope); public static final Setting TRANSPORT_SERVICE_TYPE_SETTING = - Setting.simpleString("transport.service.type", Property.NodeScope); - public static final Setting TRANSPORT_TYPE_SETTING = Setting.simpleString("transport.type", Property.NodeScope); + Setting.simpleString(TRANSPORT_SERVICE_TYPE_KEY, Property.NodeScope); + public static final Setting TRANSPORT_TYPE_SETTING = Setting.simpleString(TRANSPORT_TYPE_KEY, Property.NodeScope); diff --git a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index de2d3b75df6..5cb37d14858 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -24,11 +24,11 @@ import org.elasticsearch.action.support.AutoCreateIndex; import org.elasticsearch.action.support.DestructiveOperations; import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; import org.elasticsearch.bootstrap.BootstrapSettings; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClientNodesService; import org.elasticsearch.cluster.ClusterModule; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.InternalClusterInfoService; import org.elasticsearch.cluster.NodeConnectionsService; import org.elasticsearch.cluster.action.index.MappingUpdatedAction; diff --git a/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java index 03f27d093e8..696eb8812c9 100644 --- a/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java @@ -75,9 +75,9 @@ public class LocalDiscovery extends AbstractLifecycleComponent implem private volatile ClusterState lastProcessedClusterState; @Inject - public LocalDiscovery(Settings settings, ClusterName clusterName, ClusterService clusterService, ClusterSettings clusterSettings) { + public LocalDiscovery(Settings settings, ClusterService clusterService, ClusterSettings clusterSettings) { super(settings); - this.clusterName = clusterName; + this.clusterName = clusterService.getClusterName(); this.clusterService = clusterService; this.discoverySettings = new DiscoverySettings(settings, clusterSettings); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index 3c949b768d1..54ef9928585 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -150,12 +150,12 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen private volatile NodeJoinController nodeJoinController; @Inject - public ZenDiscovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, + public ZenDiscovery(Settings settings, ThreadPool threadPool, TransportService transportService, final ClusterService clusterService, ClusterSettings clusterSettings, ZenPingService pingService, ElectMasterService electMasterService) { super(settings); - this.clusterName = clusterName; this.clusterService = clusterService; + this.clusterName = clusterService.getClusterName(); this.transportService = transportService; this.discoverySettings = new DiscoverySettings(settings, clusterSettings); this.pingService = pingService; @@ -182,10 +182,10 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen } }); - this.masterFD = new MasterFaultDetection(settings, threadPool, transportService, clusterName, clusterService); + this.masterFD = new MasterFaultDetection(settings, threadPool, transportService, clusterService); this.masterFD.addListener(new MasterNodeFailureListener()); - this.nodesFD = new NodesFaultDetection(settings, threadPool, transportService, clusterName); + this.nodesFD = new NodesFaultDetection(settings, threadPool, transportService, clusterService.getClusterName()); this.nodesFD.addListener(new NodeFaultDetectionListener()); this.publishClusterState = @@ -195,7 +195,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen clusterService::state, new NewPendingClusterStateListener(), discoverySettings, - clusterName); + clusterService.getClusterName()); this.pingService.setPingContextProvider(this); this.membership = new MembershipAction(settings, clusterService, transportService, this, new MembershipListener()); diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java b/core/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java index d6d523508e1..807f8067490 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java @@ -76,8 +76,8 @@ public class MasterFaultDetection extends FaultDetection { private final AtomicBoolean notifiedMasterFailure = new AtomicBoolean(); public MasterFaultDetection(Settings settings, ThreadPool threadPool, TransportService transportService, - ClusterName clusterName, ClusterService clusterService) { - super(settings, threadPool, transportService, clusterName); + ClusterService clusterService) { + super(settings, threadPool, transportService, clusterService.getClusterName()); this.clusterService = clusterService; logger.debug("[master] uses ping_interval [{}], ping_timeout [{}], ping_retries [{}]", pingInterval, pingRetryTimeout, pingRetryCount); @@ -418,7 +418,7 @@ public class MasterFaultDetection extends FaultDetection { super.readFrom(in); nodeId = in.readString(); masterNodeId = in.readString(); - clusterName = ClusterName.readClusterName(in); + clusterName = new ClusterName(in); } @Override diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java b/core/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java index 74fdfe62118..6fb1c82b268 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java @@ -314,7 +314,7 @@ public class NodesFaultDetection extends FaultDetection { public void readFrom(StreamInput in) throws IOException { super.readFrom(in); nodeId = in.readString(); - clusterName = ClusterName.readClusterName(in); + clusterName = new ClusterName(in); masterNode = new DiscoveryNode(in); clusterStateVersion = in.readLong(); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java b/core/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java index e28efa044d6..06db6ab3d5c 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java @@ -32,11 +32,6 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; -import static org.elasticsearch.cluster.ClusterName.readClusterName; - -/** - * - */ public interface ZenPing extends LifecycleComponent { void setPingContextProvider(PingContextProvider contextProvider); @@ -118,7 +113,7 @@ public interface ZenPing extends LifecycleComponent { @Override public void readFrom(StreamInput in) throws IOException { - clusterName = readClusterName(in); + clusterName = new ClusterName(in); node = new DiscoveryNode(in); if (in.readBoolean()) { master = new DiscoveryNode(in); diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java b/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java index 1b4f1ba75b0..0d3c7f9d086 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java @@ -131,13 +131,13 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen private volatile boolean closed = false; @Inject - public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService transportService, ClusterName clusterName, + public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService transportService, Version version, ElectMasterService electMasterService, @Nullable Set unicastHostsProviders) { super(settings); this.threadPool = threadPool; this.transportService = transportService; - this.clusterName = clusterName; + this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); this.electMasterService = electMasterService; if (unicastHostsProviders != null) { @@ -206,10 +206,6 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen hostsProviders.add(provider); } - public void removeHostsProvider(UnicastHostsProvider provider) { - hostsProviders.remove(provider); - } - @Override public void setPingContextProvider(PingContextProvider contextProvider) { this.contextProvider = contextProvider; @@ -222,16 +218,13 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen temporalResponses.clear(); } - public PingResponse[] pingAndWait(TimeValue timeout) { + public PingResponse[] pingAndWait(TimeValue duration) { final AtomicReference response = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); - ping(new PingListener() { - @Override - public void onPing(PingResponse[] pings) { - response.set(pings); - latch.countDown(); - } - }, timeout); + ping(pings -> { + response.set(pings); + latch.countDown(); + }, duration); try { latch.await(); return response.get(); @@ -241,25 +234,26 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen } @Override - public void ping(final PingListener listener, final TimeValue timeout) { + public void ping(final PingListener listener, final TimeValue duration) { final SendPingsHandler sendPingsHandler = new SendPingsHandler(pingHandlerIdGenerator.incrementAndGet()); try { receivedResponses.put(sendPingsHandler.id(), sendPingsHandler); try { - sendPings(timeout, null, sendPingsHandler); + sendPings(duration, null, sendPingsHandler); } catch (RejectedExecutionException e) { logger.debug("Ping execution rejected", e); // The RejectedExecutionException can come from the fact unicastConnectExecutor is at its max down in sendPings // But don't bail here, we can retry later on after the send ping has been scheduled. } - threadPool.schedule(TimeValue.timeValueMillis(timeout.millis() / 2), ThreadPool.Names.GENERIC, new AbstractRunnable() { + + threadPool.schedule(TimeValue.timeValueMillis(duration.millis() / 2), ThreadPool.Names.GENERIC, new AbstractRunnable() { @Override protected void doRun() { - sendPings(timeout, null, sendPingsHandler); - threadPool.schedule(TimeValue.timeValueMillis(timeout.millis() / 2), ThreadPool.Names.GENERIC, new AbstractRunnable() { + sendPings(duration, null, sendPingsHandler); + threadPool.schedule(TimeValue.timeValueMillis(duration.millis() / 2), ThreadPool.Names.GENERIC, new AbstractRunnable() { @Override protected void doRun() throws Exception { - sendPings(timeout, TimeValue.timeValueMillis(timeout.millis() / 2), sendPingsHandler); + sendPings(duration, TimeValue.timeValueMillis(duration.millis() / 2), sendPingsHandler); sendPingsHandler.close(); listener.onPing(sendPingsHandler.pingCollection().toArray()); for (DiscoveryNode node : sendPingsHandler.nodeToDisconnect) { diff --git a/core/src/main/java/org/elasticsearch/env/Environment.java b/core/src/main/java/org/elasticsearch/env/Environment.java index 6bec05fc82b..8c8b72bff63 100644 --- a/core/src/main/java/org/elasticsearch/env/Environment.java +++ b/core/src/main/java/org/elasticsearch/env/Environment.java @@ -130,16 +130,17 @@ public class Environment { pluginsFile = homeFile.resolve("plugins"); List dataPaths = PATH_DATA_SETTING.get(settings); + final ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); if (dataPaths.isEmpty() == false) { dataFiles = new Path[dataPaths.size()]; dataWithClusterFiles = new Path[dataPaths.size()]; for (int i = 0; i < dataPaths.size(); i++) { dataFiles[i] = PathUtils.get(dataPaths.get(i)); - dataWithClusterFiles[i] = dataFiles[i].resolve(ClusterName.clusterNameFromSettings(settings).value()); + dataWithClusterFiles[i] = dataFiles[i].resolve(clusterName.value()); } } else { dataFiles = new Path[]{homeFile.resolve("data")}; - dataWithClusterFiles = new Path[]{homeFile.resolve("data").resolve(ClusterName.clusterNameFromSettings(settings).value())}; + dataWithClusterFiles = new Path[]{homeFile.resolve("data").resolve(clusterName.value())}; } if (PATH_SHARED_DATA_SETTING.exists(settings)) { sharedDataFile = PathUtils.get(cleanPath(PATH_SHARED_DATA_SETTING.get(settings))); diff --git a/core/src/main/java/org/elasticsearch/gateway/Gateway.java b/core/src/main/java/org/elasticsearch/gateway/Gateway.java index 0e6b1959279..af86633e235 100644 --- a/core/src/main/java/org/elasticsearch/gateway/Gateway.java +++ b/core/src/main/java/org/elasticsearch/gateway/Gateway.java @@ -155,7 +155,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener { final ClusterSettings clusterSettings = clusterService.getClusterSettings(); metaDataBuilder.persistentSettings(clusterSettings.archiveUnknownOrBrokenSettings(metaDataBuilder.persistentSettings())); metaDataBuilder.transientSettings(clusterSettings.archiveUnknownOrBrokenSettings(metaDataBuilder.transientSettings())); - ClusterState.Builder builder = ClusterState.builder(clusterService.state().getClusterName()); + ClusterState.Builder builder = ClusterState.builder(clusterService.getClusterName()); builder.metaData(metaDataBuilder); listener.onSuccess(builder.build()); } diff --git a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayMetaState.java b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayMetaState.java index 2d0b894939d..24886dc72d3 100644 --- a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayMetaState.java +++ b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayMetaState.java @@ -58,10 +58,10 @@ public class TransportNodesListGatewayMetaState extends TransportNodesAction responses, List failures) { - return new NodesGatewayMetaState(clusterName, responses, failures); + return new NodesGatewayMetaState(clusterService.getClusterName(), responses, failures); } @Override diff --git a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java index 675c0088082..5ae75a209eb 100644 --- a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java +++ b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java @@ -69,12 +69,12 @@ public class TransportNodesListGatewayStartedShards extends @Inject - public TransportNodesListGatewayStartedShards(Settings settings, ClusterName clusterName, ThreadPool threadPool, + public TransportNodesListGatewayStartedShards(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, NodeEnvironment env) { - super(settings, ACTION_NAME, clusterName, threadPool, clusterService, transportService, actionFilters, + super(settings, ACTION_NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver, Request::new, NodeRequest::new, ThreadPool.Names.FETCH_SHARD_STARTED, NodeGatewayStartedShards.class); this.nodeEnv = env; @@ -111,7 +111,7 @@ public class TransportNodesListGatewayStartedShards extends @Override protected NodesGatewayStartedShards newResponse(Request request, List responses, List failures) { - return new NodesGatewayStartedShards(clusterName, responses, failures); + return new NodesGatewayStartedShards(clusterService.getClusterName(), responses, failures); } @Override diff --git a/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java b/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java index 3402349743f..8766d23d3ee 100644 --- a/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java +++ b/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java @@ -351,7 +351,7 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe } private IndexShard getShard(ShardActiveRequest request) { - ClusterName thisClusterName = clusterService.state().getClusterName(); + ClusterName thisClusterName = clusterService.getClusterName(); if (!thisClusterName.equals(request.clusterName)) { logger.trace("shard exists request meant for cluster[{}], but this is cluster[{}], ignoring request", request.clusterName, thisClusterName); return null; @@ -385,7 +385,7 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - clusterName = ClusterName.readClusterName(in); + clusterName = new ClusterName(in); indexUUID = in.readString(); shardId = ShardId.readShardId(in); timeout = new TimeValue(in.readLong(), TimeUnit.MILLISECONDS); diff --git a/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java b/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java index 92c9bd3b575..da5f9d16f51 100644 --- a/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java +++ b/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java @@ -76,11 +76,11 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction responses, List failures) { - return new NodesStoreFilesMetaData(clusterName, responses, failures); + return new NodesStoreFilesMetaData(clusterService.getClusterName(), responses, failures); } @Override diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 87bfd99b900..f34e16db140 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -29,7 +29,6 @@ import org.elasticsearch.action.ActionModule; import org.elasticsearch.client.Client; import org.elasticsearch.client.node.NodeClientModule; import org.elasticsearch.cluster.ClusterModule; -import org.elasticsearch.cluster.ClusterNameModule; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.MasterNodeChangePredicate; @@ -243,6 +242,8 @@ public class Node implements Closeable { throw new IllegalStateException("Failed to created node environment", ex); } final NetworkService networkService = new NetworkService(settings); + final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool); + resourcesToClose.add(clusterService); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); ModulesBuilder modules = new ModulesBuilder(); modules.add(new Version.Module(version)); @@ -257,9 +258,8 @@ public class Node implements Closeable { modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry)); modules.add(scriptModule); modules.add(new NodeEnvironmentModule(nodeEnvironment)); - modules.add(new ClusterNameModule(this.settings)); modules.add(new DiscoveryModule(this.settings)); - modules.add(new ClusterModule(this.settings)); + modules.add(new ClusterModule(this.settings, clusterService)); modules.add(new IndicesModule()); modules.add(new SearchModule(settings, namedWriteableRegistry)); modules.add(new ActionModule(DiscoveryNode.isIngestNode(settings), false)); diff --git a/core/src/main/java/org/elasticsearch/transport/TransportService.java b/core/src/main/java/org/elasticsearch/transport/TransportService.java index c8f7be07b94..21a43560eba 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportService.java @@ -77,7 +77,7 @@ public class TransportService extends AbstractLifecycleComponent requestHandlers = Collections.emptyMap(); @@ -117,16 +117,12 @@ public class TransportService extends AbstractLifecycleComponent, NodeRequest extends BaseNodeRequest> extends TransportNodesAction { - AbstractTestNodesAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool, + AbstractTestNodesAction(Settings settings, String actionName, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, Supplier request, Supplier nodeRequest) { - super(settings, actionName, clusterName, threadPool, clusterService, transportService, + super(settings, actionName, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(Settings.EMPTY), request, nodeRequest, ThreadPool.Names.GENERIC, NodeResponse.class); } @Override protected NodesResponse newResponse(NodesRequest request, List responses, List failures) { - return new NodesResponse(clusterName, responses, failures); + return new NodesResponse(clusterService.getClusterName(), responses, failures); } @Override @@ -166,10 +166,9 @@ public abstract class TaskManagerTestCase extends ESTestCase { public static class TestNode implements Releasable { public TestNode(String name, ThreadPool threadPool, Settings settings) { clusterService = createClusterService(threadPool); - ClusterName clusterName = clusterService.state().getClusterName(); transportService = new TransportService(settings, new LocalTransport(settings, threadPool, Version.CURRENT, new NamedWriteableRegistry(), - new NoneCircuitBreakerService()), threadPool, clusterName) { + new NoneCircuitBreakerService()), threadPool) { @Override protected TaskManager createTaskManager() { if (MockTaskManager.USE_MOCK_TASK_MANAGER_SETTING.get(settings)) { @@ -185,9 +184,9 @@ public abstract class TaskManagerTestCase extends ESTestCase { emptyMap(), emptySet(), Version.CURRENT); IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(settings); ActionFilters actionFilters = new ActionFilters(emptySet()); - transportListTasksAction = new TransportListTasksAction(settings, CLUSTER_NAME, threadPool, clusterService, transportService, + transportListTasksAction = new TransportListTasksAction(settings, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver); - transportCancelTasksAction = new TransportCancelTasksAction(settings, CLUSTER_NAME, threadPool, clusterService, + transportCancelTasksAction = new TransportCancelTasksAction(settings, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver); transportService.acceptIncomingRequests(); } diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java index 11b83d67a8c..8f8c10c8dda 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java @@ -246,9 +246,9 @@ public class TestTaskPlugin extends Plugin { public static class TransportTestTaskAction extends TransportNodesAction { @Inject - public TransportTestTaskAction(Settings settings, ClusterName clusterName, ThreadPool threadPool, + public TransportTestTaskAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService) { - super(settings, TestTaskAction.NAME, clusterName, threadPool, clusterService, transportService, + super(settings, TestTaskAction.NAME, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(Settings.EMPTY), NodesRequest::new, NodeRequest::new, ThreadPool.Names.GENERIC, NodeResponse.class); } @@ -258,7 +258,7 @@ public class TestTaskPlugin extends Plugin { if (request.getShouldFail()) { throw new IllegalStateException("Simulating operation failure"); } - return new NodesResponse(clusterName, responses, failures); + return new NodesResponse(clusterService.getClusterName(), responses, failures); } @Override @@ -425,10 +425,10 @@ public class TestTaskPlugin extends Plugin { UnblockTestTasksResponse, UnblockTestTaskResponse> { @Inject - public TransportUnblockTestTasksAction(Settings settings, ClusterName clusterName, ThreadPool threadPool, ClusterService + public TransportUnblockTestTasksAction(Settings settings,ThreadPool threadPool, ClusterService clusterService, TransportService transportService) { - super(settings, UnblockTestTasksAction.NAME, clusterName, threadPool, clusterService, transportService, new ActionFilters(new + super(settings, UnblockTestTasksAction.NAME, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(Settings.EMPTY), UnblockTestTasksRequest::new, UnblockTestTasksResponse::new, ThreadPool.Names.MANAGEMENT); } diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java index 326e909b3ff..c4d49d899b9 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java @@ -35,7 +35,6 @@ import org.elasticsearch.action.support.nodes.BaseNodesRequest; import org.elasticsearch.action.support.tasks.BaseTasksRequest; import org.elasticsearch.action.support.tasks.BaseTasksResponse; import org.elasticsearch.action.support.tasks.TransportTasksAction; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; @@ -170,9 +169,9 @@ public class TransportTasksActionTests extends TaskManagerTestCase { */ abstract class TestNodesAction extends AbstractTestNodesAction { - TestNodesAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool, + TestNodesAction(Settings settings, String actionName, ThreadPool threadPool, ClusterService clusterService, TransportService transportService) { - super(settings, actionName, clusterName, threadPool, clusterService, transportService, NodesRequest::new, NodeRequest::new); + super(settings, actionName, threadPool, clusterService, transportService, NodesRequest::new, NodeRequest::new); } @Override @@ -252,9 +251,9 @@ public class TransportTasksActionTests extends TaskManagerTestCase { */ static abstract class TestTasksAction extends TransportTasksAction { - protected TestTasksAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool, + protected TestTasksAction(Settings settings, String actionName, ThreadPool threadPool, ClusterService clusterService, TransportService transportService) { - super(settings, actionName, clusterName, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), + super(settings, actionName, threadPool, clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(Settings.EMPTY), TestTasksRequest::new, TestTasksResponse::new, ThreadPool.Names.MANAGEMENT); } @@ -298,7 +297,7 @@ public class TransportTasksActionTests extends TaskManagerTestCase { TestNodesAction[] actions = new TestNodesAction[nodesCount]; for (int i = 0; i < testNodes.length; i++) { final int node = i; - actions[i] = new TestNodesAction(Settings.EMPTY, "testAction", CLUSTER_NAME, threadPool, testNodes[i].clusterService, + actions[i] = new TestNodesAction(CLUSTER_SETTINGS, "testAction", threadPool, testNodes[i].clusterService, testNodes[i].transportService) { @Override protected NodeResponse nodeOperation(NodeRequest request) { @@ -583,7 +582,7 @@ public class TransportTasksActionTests extends TaskManagerTestCase { RecordingTaskManagerListener[] listeners = setupListeners(testNodes, "testAction*"); for (int i = 0; i < testNodes.length; i++) { final int node = i; - actions[i] = new TestNodesAction(Settings.EMPTY, "testAction", CLUSTER_NAME, threadPool, testNodes[i].clusterService, + actions[i] = new TestNodesAction(CLUSTER_SETTINGS, "testAction", threadPool, testNodes[i].clusterService, testNodes[i].transportService) { @Override protected NodeResponse nodeOperation(NodeRequest request) { @@ -623,7 +622,7 @@ public class TransportTasksActionTests extends TaskManagerTestCase { for (int i = 0; i < testNodes.length; i++) { final int node = i; // Simulate task action that fails on one of the tasks on one of the nodes - tasksActions[i] = new TestTasksAction(Settings.EMPTY, "testTasksAction", CLUSTER_NAME, threadPool, testNodes[i].clusterService, + tasksActions[i] = new TestTasksAction(CLUSTER_SETTINGS, "testTasksAction", threadPool, testNodes[i].clusterService, testNodes[i].transportService) { @Override protected TestTaskResponse taskOperation(TestTasksRequest request, Task task) { @@ -681,7 +680,7 @@ public class TransportTasksActionTests extends TaskManagerTestCase { final int node = i; // Simulate a task action that works on all nodes except nodes listed in filterNodes. // We are testing that it works. - tasksActions[i] = new TestTasksAction(Settings.EMPTY, "testTasksAction", CLUSTER_NAME, threadPool, + tasksActions[i] = new TestTasksAction(CLUSTER_SETTINGS, "testTasksAction", threadPool, testNodes[i].clusterService, testNodes[i].transportService) { @Override diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java index c11bf0b9ca6..00fcbf60a5a 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java @@ -163,7 +163,8 @@ public class ClusterRerouteTests extends ESAllocationTestCase { routingTableBuilder.addAsNew(metaData.index("idx")); RoutingTable routingTable = routingTableBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING + .getDefault(Settings.EMPTY)) .metaData(metaData).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))) .build(); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/shrink/TransportShrinkActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/shrink/TransportShrinkActionTests.java index 01be8da8944..d78374d446f 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/shrink/TransportShrinkActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/shrink/TransportShrinkActionTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.indices.shrink; import org.apache.lucene.index.IndexWriter; import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.EmptyClusterInfoService; import org.elasticsearch.cluster.block.ClusterBlocks; @@ -61,7 +62,7 @@ public class TransportShrinkActionTests extends ESTestCase { routingTableBuilder.addAsNew(metaData.index(name)); RoutingTable routingTable = routingTableBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData).routingTable(routingTable).blocks(ClusterBlocks.builder().addBlocks(indexMetaData)).build(); return clusterState; } diff --git a/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java b/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java index 908fb2ddd4d..6ae7559ba62 100644 --- a/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java +++ b/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java @@ -87,7 +87,7 @@ public class TransportBulkActionTookTests extends ESTestCase { private TransportBulkAction createAction(boolean controlled, AtomicLong expected) { CapturingTransport capturingTransport = new CapturingTransport(); - TransportService transportService = new TransportService(capturingTransport, threadPool, clusterService.state().getClusterName()); + TransportService transportService = new TransportService(clusterService.getSettings(), capturingTransport, threadPool); transportService.start(); transportService.acceptIncomingRequests(); IndexNameExpressionResolver resolver = new Resolver(Settings.EMPTY); diff --git a/core/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java b/core/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java index 40359e1c749..9572a2df652 100644 --- a/core/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java @@ -142,6 +142,6 @@ public class AutoCreateIndexTests extends ESTestCase { for (String index : indices) { metaData.put(IndexMetaData.builder(index).settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)); } - return ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).build(); + return ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).build(); } } diff --git a/core/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java b/core/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java index 07ddfa8e49f..1d65f277e3c 100644 --- a/core/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java @@ -191,7 +191,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase { super.setUp(); transport = new CapturingTransport(); clusterService = createClusterService(THREAD_POOL); - final TransportService transportService = new TransportService(transport, THREAD_POOL, clusterService.state().getClusterName()); + final TransportService transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL); transportService.start(); transportService.acceptIncomingRequests(); setClusterState(clusterService, TEST_INDEX); diff --git a/core/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java b/core/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java index d6edb972ef4..32fe6b1e408 100644 --- a/core/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java @@ -86,7 +86,7 @@ public class TransportMasterNodeActionTests extends ESTestCase { super.setUp(); transport = new CapturingTransport(); clusterService = createClusterService(threadPool); - transportService = new TransportService(transport, threadPool, clusterService.state().getClusterName()); + transportService = new TransportService(clusterService.getSettings(), transport, threadPool); transportService.start(); transportService.acceptIncomingRequests(); localNode = new DiscoveryNode("local_node", DummyTransportAddress.INSTANCE, Collections.emptyMap(), diff --git a/core/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java b/core/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java index 1b0a6f8d622..626850fd119 100644 --- a/core/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java @@ -63,7 +63,6 @@ import static org.mockito.Mockito.mock; public class TransportNodesActionTests extends ESTestCase { private static ThreadPool THREAD_POOL; - private static ClusterName CLUSTER_NAME = new ClusterName("test-cluster"); private ClusterService clusterService; private CapturingTransport transport; @@ -178,7 +177,7 @@ public class TransportNodesActionTests extends ESTestCase { super.setUp(); transport = new CapturingTransport(); clusterService = createClusterService(THREAD_POOL); - transportService = new TransportService(transport, THREAD_POOL, clusterService.state().getClusterName()); + transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL); transportService.start(); transportService.acceptIncomingRequests(); int numNodes = randomIntBetween(3, 10); @@ -196,7 +195,7 @@ public class TransportNodesActionTests extends ESTestCase { } discoBuilder.localNodeId(randomFrom(discoveryNodes).getId()); discoBuilder.masterNodeId(randomFrom(discoveryNodes).getId()); - ClusterState.Builder stateBuilder = ClusterState.builder(CLUSTER_NAME); + ClusterState.Builder stateBuilder = ClusterState.builder(clusterService.getClusterName()); stateBuilder.nodes(discoBuilder); ClusterState clusterState = stateBuilder.build(); setState(clusterService, clusterState); @@ -246,14 +245,14 @@ public class TransportNodesActionTests extends ESTestCase { TestTransportNodesAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, Supplier request, Supplier nodeRequest, String nodeExecutor) { - super(settings, "indices:admin/test", CLUSTER_NAME, threadPool, clusterService, transportService, actionFilters, + super(settings, "indices:admin/test", threadPool, clusterService, transportService, actionFilters, null, request, nodeRequest, nodeExecutor, TestNodeResponse.class); } @Override protected TestNodesResponse newResponse(TestNodesRequest request, List responses, List failures) { - return new TestNodesResponse(request, responses, failures); + return new TestNodesResponse(clusterService.getClusterName(), request, responses, failures); } @Override @@ -302,8 +301,9 @@ public class TransportNodesActionTests extends ESTestCase { private final TestNodesRequest request; - TestNodesResponse(TestNodesRequest request, List nodeResponses, List failures) { - super(CLUSTER_NAME, nodeResponses, failures); + TestNodesResponse(ClusterName clusterName, TestNodesRequest request, List nodeResponses, + List failures) { + super(clusterName, nodeResponses, failures); this.request = request; } diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java index ea4e55c02f4..abebb61c0b7 100644 --- a/core/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java @@ -91,7 +91,7 @@ public class BroadcastReplicationTests extends ESTestCase { super.setUp(); LocalTransport transport = new LocalTransport(Settings.EMPTY, threadPool, Version.CURRENT, new NamedWriteableRegistry(), circuitBreakerService); clusterService = createClusterService(threadPool); - transportService = new TransportService(transport, threadPool, clusterService.state().getClusterName()); + transportService = new TransportService(clusterService.getSettings(), transport, threadPool); transportService.start(); transportService.acceptIncomingRequests(); broadcastReplicationAction = new TestBroadcastReplicationAction(Settings.EMPTY, threadPool, clusterService, transportService, new ActionFilters(new HashSet()), new IndexNameExpressionResolver(Settings.EMPTY), null); diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java index 8ee2499d040..229e3b6635e 100644 --- a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java @@ -119,7 +119,7 @@ public class TransportReplicationActionTests extends ESTestCase { super.setUp(); transport = new CapturingTransport(); clusterService = createClusterService(threadPool); - transportService = new TransportService(transport, threadPool, clusterService.state().getClusterName()); + transportService = new TransportService(clusterService.getSettings(), transport, threadPool); transportService.start(); transportService.acceptIncomingRequests(); action = new Action(Settings.EMPTY, "testAction", transportService, clusterService, threadPool); diff --git a/core/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java b/core/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java index 6d7ac6128c9..c26d376b587 100644 --- a/core/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java @@ -142,7 +142,7 @@ public class TransportInstanceSingleOperationActionTests extends ESTestCase { super.setUp(); transport = new CapturingTransport(); clusterService = createClusterService(THREAD_POOL); - transportService = new TransportService(transport, THREAD_POOL, clusterService.state().getClusterName()); + transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL); transportService.start(); transportService.acceptIncomingRequests(); action = new TestTransportInstanceSingleOperationAction( diff --git a/core/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTestCase.java b/core/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTestCase.java index fb23f024b5d..208945a6179 100644 --- a/core/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTestCase.java +++ b/core/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTestCase.java @@ -238,7 +238,7 @@ public abstract class AbstractTermVectorsTestCase extends ESIntegTestCase { contentArray[j] = fieldContentOptions[randomInt(fieldContentOptions.length - 1)]; docSource.put(fieldSettings[j].name, contentArray[j]); } - final String id = routingKeyForShard(index, "type", i); + final String id = routingKeyForShard(index, i); TestDoc doc = new TestDoc(id, fieldSettings, contentArray.clone()); index(doc.index, doc.type, doc.id, docSource); testDocs[i] = doc; diff --git a/core/src/test/java/org/elasticsearch/client/transport/FailAndRetryMockTransport.java b/core/src/test/java/org/elasticsearch/client/transport/FailAndRetryMockTransport.java index 50fbbd4fcb8..c085c3164a0 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/FailAndRetryMockTransport.java +++ b/core/src/test/java/org/elasticsearch/client/transport/FailAndRetryMockTransport.java @@ -27,6 +27,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.Lifecycle; import org.elasticsearch.common.component.LifecycleListener; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.transport.ConnectTransportException; @@ -74,7 +75,8 @@ abstract class FailAndRetryMockTransport imp //we make sure that nodes get added to the connected ones when calling addTransportAddress, by returning proper nodes info if (connectMode) { TransportResponseHandler transportResponseHandler = transportServiceAdapter.onResponseReceived(requestId); - transportResponseHandler.handleResponse(new LivenessResponse(ClusterName.DEFAULT, node)); + transportResponseHandler.handleResponse(new LivenessResponse(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY), + node)); return; } diff --git a/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java b/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java index e26ebfefcc9..eee74b66148 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java +++ b/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java @@ -67,6 +67,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTestCase { TransportClient client = TransportClient.builder() .settings(Settings.builder() .put("client.transport.sniff", false) + .put("cluster.name", "cluster1") .put("node.name", "transport_client_" + this.getTestName()) .put(headersSettings) .build()) @@ -115,8 +116,8 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTestCase { CountDownLatch clusterStateLatch = new CountDownLatch(1); @Inject - public InternalTransportService(Settings settings, Transport transport, ThreadPool threadPool, ClusterName clusterName) { - super(settings, transport, threadPool, clusterName); + public InternalTransportService(Settings settings, Transport transport, ThreadPool threadPool) { + super(settings, transport, threadPool); } @Override @SuppressWarnings("unchecked") @@ -124,7 +125,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTestCase { TransportRequestOptions options, TransportResponseHandler handler) { if (TransportLivenessAction.NAME.equals(action)) { assertHeaders(threadPool); - ((TransportResponseHandler) handler).handleResponse(new LivenessResponse(ClusterName.DEFAULT, node)); + ((TransportResponseHandler) handler).handleResponse(new LivenessResponse(clusterName, node)); return; } if (ClusterStateAction.NAME.equals(action)) { diff --git a/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java b/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java index 0dddb301444..2a32ebd05af 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java +++ b/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java @@ -63,7 +63,8 @@ public class TransportClientNodesServiceTests extends ESTestCase { private final int nodesCount; TestIteration() { - ClusterName clusterName = new ClusterName("test"); + Settings settings = Settings.builder().put("cluster.name", "test").build(); + ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); threadPool = new TestThreadPool("transport-client-nodes-service-tests"); transport = new FailAndRetryMockTransport(random(), clusterName) { @Override @@ -76,7 +77,7 @@ public class TransportClientNodesServiceTests extends ESTestCase { return new TestResponse(); } }; - transportService = new TransportService(Settings.EMPTY, transport, threadPool, clusterName) { + transportService = new TransportService(settings, transport, threadPool) { @Override public void sendRequest(DiscoveryNode node, String action, TransportRequest request, final TransportResponseHandler handler) { @@ -101,7 +102,7 @@ public class TransportClientNodesServiceTests extends ESTestCase { transportService.start(); transportService.acceptIncomingRequests(); transportClientNodesService = - new TransportClientNodesService(Settings.EMPTY, clusterName, transportService, threadPool, Version.CURRENT); + new TransportClientNodesService(settings, transportService, threadPool, Version.CURRENT); this.nodesCount = randomIntBetween(1, 10); for (int i = 0; i < nodesCount; i++) { transportClientNodesService.addTransportAddresses(new LocalTransportAddress("node" + i)); diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index 98bb013f308..514968d1643 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllo import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.ModuleTestCase; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.IndexScopedSettings; @@ -40,7 +41,8 @@ import org.elasticsearch.common.settings.SettingsModule; import java.util.HashMap; import java.util.Map; public class ClusterModuleTests extends ModuleTestCase { - + private ClusterService clusterService = new ClusterService(Settings.EMPTY, + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null); public static class FakeAllocationDecider extends AllocationDecider { protected FakeAllocationDecider(Settings settings) { super(settings); @@ -97,7 +99,7 @@ public class ClusterModuleTests extends ModuleTestCase { } public void testRegisterAllocationDeciderDuplicate() { - ClusterModule module = new ClusterModule(Settings.EMPTY); + ClusterModule module = new ClusterModule(Settings.EMPTY, clusterService); try { module.registerAllocationDecider(EnableAllocationDecider.class); } catch (IllegalArgumentException e) { @@ -107,20 +109,20 @@ public class ClusterModuleTests extends ModuleTestCase { } public void testRegisterAllocationDecider() { - ClusterModule module = new ClusterModule(Settings.EMPTY); + ClusterModule module = new ClusterModule(Settings.EMPTY, clusterService); module.registerAllocationDecider(FakeAllocationDecider.class); assertSetMultiBinding(module, AllocationDecider.class, FakeAllocationDecider.class); } public void testRegisterShardsAllocator() { Settings settings = Settings.builder().put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), "custom").build(); - ClusterModule module = new ClusterModule(settings); + ClusterModule module = new ClusterModule(settings, clusterService); module.registerShardsAllocator("custom", FakeShardsAllocator.class); assertBinding(module, ShardsAllocator.class, FakeShardsAllocator.class); } public void testRegisterShardsAllocatorAlreadyRegistered() { - ClusterModule module = new ClusterModule(Settings.EMPTY); + ClusterModule module = new ClusterModule(Settings.EMPTY, clusterService); try { module.registerShardsAllocator(ClusterModule.BALANCED_ALLOCATOR, FakeShardsAllocator.class); } catch (IllegalArgumentException e) { @@ -130,19 +132,19 @@ public class ClusterModuleTests extends ModuleTestCase { public void testUnknownShardsAllocator() { Settings settings = Settings.builder().put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), "dne").build(); - ClusterModule module = new ClusterModule(settings); + ClusterModule module = new ClusterModule(settings, clusterService); assertBindingFailure(module, "Unknown [shards_allocator]"); } public void testEvenShardsAllocatorBackcompat() { Settings settings = Settings.builder() .put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), ClusterModule.EVEN_SHARD_COUNT_ALLOCATOR).build(); - ClusterModule module = new ClusterModule(settings); + ClusterModule module = new ClusterModule(settings, clusterService); assertBinding(module, ShardsAllocator.class, BalancedShardsAllocator.class); } public void testRegisterIndexTemplateFilterDuplicate() { - ClusterModule module = new ClusterModule(Settings.EMPTY); + ClusterModule module = new ClusterModule(Settings.EMPTY, clusterService); try { module.registerIndexTemplateFilter(FakeIndexTemplateFilter.class); module.registerIndexTemplateFilter(FakeIndexTemplateFilter.class); @@ -153,7 +155,7 @@ public class ClusterModuleTests extends ModuleTestCase { } public void testRegisterIndexTemplateFilter() { - ClusterModule module = new ClusterModule(Settings.EMPTY); + ClusterModule module = new ClusterModule(Settings.EMPTY, clusterService); module.registerIndexTemplateFilter(FakeIndexTemplateFilter.class); assertSetMultiBinding(module, IndexTemplateFilter.class, FakeIndexTemplateFilter.class); } diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java b/core/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java index 92be2331a8c..5e272a27459 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.cluster; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.test.ESTestCase; @@ -34,11 +35,15 @@ public class ClusterStateTests extends ESTestCase { final DiscoveryNode node1 = new DiscoveryNode("node1", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT); final DiscoveryNode node2 = new DiscoveryNode("node2", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT); final DiscoveryNodes nodes = DiscoveryNodes.builder().put(node1).put(node2).build(); - ClusterState noMaster1 = ClusterState.builder(ClusterName.DEFAULT).version(randomInt(5)).nodes(nodes).build(); - ClusterState noMaster2 = ClusterState.builder(ClusterName.DEFAULT).version(randomInt(5)).nodes(nodes).build(); - ClusterState withMaster1a = ClusterState.builder(ClusterName.DEFAULT).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node1.getId())).build(); - ClusterState withMaster1b = ClusterState.builder(ClusterName.DEFAULT).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node1.getId())).build(); - ClusterState withMaster2 = ClusterState.builder(ClusterName.DEFAULT).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node2.getId())).build(); + ClusterName name = ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY); + ClusterState noMaster1 = ClusterState.builder(name).version(randomInt(5)).nodes(nodes).build(); + ClusterState noMaster2 = ClusterState.builder(name).version(randomInt(5)).nodes(nodes).build(); + ClusterState withMaster1a = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes) + .masterNodeId(node1.getId())).build(); + ClusterState withMaster1b = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes) + .masterNodeId(node1.getId())).build(); + ClusterState withMaster2 = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes) + .masterNodeId(node2.getId())).build(); // states with no master should never supersede anything assertFalse(noMaster1.supersedes(noMaster2)); diff --git a/core/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java index a3bb73977e7..5eb5a34c44f 100644 --- a/core/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java @@ -149,7 +149,7 @@ public class NodeConnectionsServiceTests extends ESTestCase { public void setUp() throws Exception { super.setUp(); this.transport = new MockTransport(); - transportService = new TransportService(transport, THREAD_POOL, ClusterName.DEFAULT); + transportService = new TransportService(Settings.EMPTY, transport, THREAD_POOL); transportService.start(); transportService.acceptIncomingRequests(); } diff --git a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java index 426a574e2cd..1faac874114 100644 --- a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java @@ -84,7 +84,7 @@ public class ShardFailedClusterStateTaskExecutorTests extends ESAllocationTestCa routingTable = RoutingTable.builder() .addAsNew(metaData.index(INDEX)) .build(); - clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); executor = new ShardStateAction.ShardFailedClusterStateTaskExecutor(allocationService, null, logger); } diff --git a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java index bfc3929dd14..7f0ac1a6e45 100644 --- a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java @@ -107,7 +107,7 @@ public class ShardStateActionTests extends ESTestCase { super.setUp(); this.transport = new CapturingTransport(); clusterService = createClusterService(THREAD_POOL); - transportService = new TransportService(transport, THREAD_POOL, clusterService.state().getClusterName()); + transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL); transportService.start(); transportService.acceptIncomingRequests(); shardStateAction = new TestShardStateAction(Settings.EMPTY, clusterService, transportService, null, null); diff --git a/core/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java b/core/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java index e99c862bfec..fd1e3e62466 100644 --- a/core/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java @@ -81,7 +81,7 @@ public class ClusterStateHealthTests extends ESTestCase { public void setUp() throws Exception { super.setUp(); clusterService = createClusterService(threadPool); - transportService = new TransportService(new CapturingTransport(), threadPool, clusterService.state().getClusterName()); + transportService = new TransportService(clusterService.getSettings(), new CapturingTransport(), threadPool); transportService.start(); transportService.acceptIncomingRequests(); } @@ -127,8 +127,7 @@ public class ClusterStateHealthTests extends ESTestCase { listenerCalled.await(); TransportClusterHealthAction action = new TransportClusterHealthAction(Settings.EMPTY, transportService, - clusterService, threadPool, clusterService.state().getClusterName(), new ActionFilters(new HashSet<>()), - indexNameExpressionResolver, NoopGatewayAllocator.INSTANCE); + clusterService, threadPool, new ActionFilters(new HashSet<>()), indexNameExpressionResolver, NoopGatewayAllocator.INSTANCE); PlainActionFuture listener = new PlainActionFuture<>(); action.execute(new ClusterHealthRequest(), listener); @@ -158,7 +157,7 @@ public class ClusterStateHealthTests extends ESTestCase { metaData.put(indexMetaData, true); routingTable.add(indexRoutingTable); } - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable.build()).build(); + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable.build()).build(); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), (String[]) null); ClusterStateHealth clusterStateHealth = new ClusterStateHealth(clusterState, concreteIndices); logger.info("cluster status: {}, expected {}", clusterStateHealth.getStatus(), counter.status()); diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java index 53dffc799b1..28a25d17337 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java @@ -61,7 +61,8 @@ public class MetaDataCreateIndexServiceTests extends ESTestCase { routingTableBuilder.addAsNew(metaData.index(name)); RoutingTable routingTable = routingTableBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING + .getDefault(Settings.EMPTY)) .metaData(metaData).routingTable(routingTable).blocks(ClusterBlocks.builder().addBlocks(indexMetaData)).build(); return clusterState; } @@ -200,7 +201,8 @@ public class MetaDataCreateIndexServiceTests extends ESTestCase { private void validateIndexName(String indexName, String errorMessage) { InvalidIndexNameException e = expectThrows(InvalidIndexNameException.class, - () -> getCreateIndexService().validateIndexName(indexName, ClusterState.builder(ClusterName.DEFAULT).build())); + () -> getCreateIndexService().validateIndexName(indexName, ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING + .getDefault(Settings.EMPTY)).build())); assertThat(e.getMessage(), endsWith(errorMessage)); } diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java index 2e1cdea56a4..14f4ccf5581 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java @@ -92,7 +92,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase { .put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "0")) .numberOfShards(1).numberOfReplicas(1)) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build(); clusterState = ClusterState.builder(clusterState) @@ -138,7 +138,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase { .put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), delaySetting)) .numberOfShards(1).numberOfReplicas(1)) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build(); clusterState = ClusterState.builder(clusterState) @@ -236,7 +236,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase { .settings(settings(Version.CURRENT).put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), longDelaySetting)) .numberOfShards(1).numberOfReplicas(1)) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index("short_delay")).addAsNew(metaData.index("long_delay")).build()) .nodes(DiscoveryNodes.builder() .put(newNode("node0", singleton(DiscoveryNode.Role.MASTER))).localNodeId("node0").masterNodeId("node0") @@ -390,7 +390,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase { .put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), shorterDelaySetting)) .numberOfShards(1).numberOfReplicas(1)) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder() .addAsNew(metaData.index("foo")) diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java index 0127702c5ea..370ac52956c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.support.replication.ClusterStateCreationUtils; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; @@ -210,7 +211,8 @@ public class OperationRoutingTests extends ESTestCase{ } } final ShardIterator it = - new OperationRouting(Settings.EMPTY, new AwarenessAllocationDecider()) + new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, + ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) .getShards(clusterService.state(), indexName, 0, "_prefer_nodes:" + String.join(",", nodes)); final List all = new ArrayList<>(); ShardRouting shard; diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java index c78b1f9c815..4dceb42cfbc 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java @@ -79,8 +79,8 @@ public class PrimaryTermsTests extends ESAllocationTestCase { .build()) .build(); - this.clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData) - .routingTable(testRoutingTable).build(); + this.clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) + .metaData(metaData).routingTable(testRoutingTable).build(); } /** diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java index d8dedb1e8e8..c673a6fd226 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.VersionUtils; @@ -36,7 +37,8 @@ import java.util.Arrays; public class RoutingBackwardCompatibilityTests extends ESTestCase { public void testBackwardCompatibility() throws Exception { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(RoutingBackwardCompatibilityTests.class.getResourceAsStream("/org/elasticsearch/cluster/routing/shard_routes.txt"), "UTF-8"))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(RoutingBackwardCompatibilityTests.class + .getResourceAsStream("/org/elasticsearch/cluster/routing/shard_routes.txt"), "UTF-8"))) { for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (line.startsWith("#")) { // comment continue; @@ -51,17 +53,20 @@ public class RoutingBackwardCompatibilityTests extends ESTestCase { final int pre20ExpectedShardId = Integer.parseInt(parts[5]); // not needed anymore - old hashing is gone final int currentExpectedShard = Integer.parseInt(parts[6]); - OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, null); + OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, + ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); for (Version version : VersionUtils.allVersions()) { if (version.onOrAfter(Version.V_2_0_0) == false) { // unsupported version, no need to test continue; } final Settings settings = settings(version).build(); - IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(settings).numberOfShards(numberOfShards).numberOfReplicas(randomInt(3)).build(); + IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(settings).numberOfShards(numberOfShards) + .numberOfReplicas(randomInt(3)).build(); MetaData.Builder metaData = MetaData.builder().put(indexMetaData, false); RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetaData).build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) + .metaData(metaData).routingTable(routingTable).build(); final int shardId = operationRouting.indexShards(clusterState, index, id, routing).shardId().getId(); assertEquals(currentExpectedShard, shardId); } diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java index 9e2b1df3696..2d1a467a001 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java @@ -73,7 +73,7 @@ public class RoutingTableTests extends ESAllocationTestCase { .add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_1).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_1)).build()) .add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_2).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_2)).build()) .build(); - this.clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(testRoutingTable).build(); + this.clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(testRoutingTable).build(); } /** diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java index 82703c6f29e..75300a4beb8 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java @@ -94,7 +94,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build(); for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) { @@ -106,7 +106,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsRecovery(metaData.index("test")).build()).build(); for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) { @@ -118,7 +118,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsFromCloseToOpen(metaData.index("test")).build()).build(); for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) { @@ -130,7 +130,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNewRestore(metaData.index("test"), new RestoreSource(new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID())), Version.CURRENT, "test"), new IntHashSet()).build()).build(); for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) { @@ -142,7 +142,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsRestore(metaData.index("test"), new RestoreSource(new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID())), Version.CURRENT, "test")).build()).build(); for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) { @@ -154,7 +154,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsFromDangling(metaData.index("test")).build()).build(); for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) { @@ -168,7 +168,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(0)) .build(); final Index index = metaData.index("test").getIndex(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index(index)).build()).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); @@ -208,7 +208,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -237,7 +237,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -286,7 +286,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { .put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)) .put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build()).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -314,7 +314,7 @@ public class UnassignedInfoTests extends ESAllocationTestCase { .put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT).put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), delayTest1)).numberOfShards(1).numberOfReplicas(1)) .put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT).put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), delayTest2)).numberOfShards(1).numberOfReplicas(1)) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build()).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ActiveAllocationIdTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ActiveAllocationIdTests.java index 2e54512b95f..b3679208276 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ActiveAllocationIdTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ActiveAllocationIdTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESAllocationTestCase; import java.util.Arrays; @@ -50,7 +51,8 @@ public class ActiveAllocationIdTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING + .getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("adding three nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put( diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java index fe4937eea7e..cf90379a50f 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java @@ -306,7 +306,7 @@ public class AddIncrementallyTests extends ESAllocationTestCase { for (int i = 0; i < numberOfNodes; i++) { nodes.put(newNode("node" + i)); } - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).nodes(nodes).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(routingTable).build(); routingTable = service.reroute(clusterState, "reroute").routingTable(); clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); RoutingNodes routingNodes = clusterState.getRoutingNodes(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java index 0d637e451f0..28f27b8988c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java @@ -76,7 +76,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -133,7 +133,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsRecovery(metaData.index(index)) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); final ShardId shardId = new ShardId(metaData.index(index).getIndex(), 0); logger.info("--> adding 3 nodes on same rack and do rerouting"); @@ -256,7 +256,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding 3 nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java index f12ed123dc5..86f3bd5704b 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java @@ -65,7 +65,7 @@ public class AllocationPriorityTests extends ESAllocationTestCase { .addAsNew(metaData.index("first")) .addAsNew(metaData.index("second")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute"); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java index 805ab0321ba..d78156b2217 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java @@ -68,7 +68,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -136,7 +136,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -210,7 +210,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -301,7 +301,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -392,7 +392,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -470,7 +470,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -551,7 +551,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -618,7 +618,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -693,7 +693,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -772,7 +772,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes in different zones and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -833,7 +833,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding 5 nodes in different zones and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java index e606f007dee..9d0b27eac1a 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java @@ -131,7 +131,7 @@ public class BalanceConfigurationTests extends ESAllocationTestCase { for (int i = 0; i < numberOfNodes; i++) { nodes.put(newNode("node" + i)); } - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).nodes(nodes).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(routingTable).build(); routingTable = strategy.reroute(clusterState, "reroute").routingTable(); clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); RoutingNodes routingNodes = clusterState.getRoutingNodes(); @@ -381,7 +381,7 @@ public class BalanceConfigurationTests extends ESAllocationTestCase { nodes.put(node); } - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).nodes(nodes).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(routingTable).build(); routingTable = strategy.reroute(clusterState, "reroute").routingTable(); clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); RoutingNodes routingNodes = clusterState.getRoutingNodes(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java index 2483832ef71..fe264e17378 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java @@ -120,7 +120,7 @@ public abstract class CatAllocationTestCase extends ESAllocationTestCase { for (String node : nodes) { builderDiscoNodes.put(newNode(node)); } - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).nodes(builderDiscoNodes.build()).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).nodes(builderDiscoNodes.build()).build(); if (balanceFirst()) { clusterState = rebalance(clusterState); } diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java index 4e99d69ef89..95ce9d668ea 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java @@ -60,7 +60,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -146,7 +146,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -250,7 +250,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -334,7 +334,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -457,7 +457,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -541,7 +541,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -661,7 +661,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test1")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); @@ -760,7 +760,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test1")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java index 0fcffb8afe3..5d8cdcb838f 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java @@ -57,7 +57,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(5)); for (int i = 0; i < routingTable.index("test").shards().size(); i++) { diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java index b14aeca890e..856d8361779 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java @@ -56,7 +56,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding 2 nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -107,7 +107,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding 2 nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -181,7 +181,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding 2 nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java index 0bf3ca93676..83a4c17a631 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java @@ -55,7 +55,7 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ESAllocationTest .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java index 19591eef425..7d2ffb07ddf 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java @@ -78,7 +78,7 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding one node and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); routingTable = strategy.reroute(clusterState, "reroute").routingTable(); @@ -130,7 +130,7 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java index ecf7ca741b4..3b5332eb237 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java @@ -54,7 +54,7 @@ public class FailedNodeRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start 4 nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2")).put(newNode("node3")).put(newNode("node4"))).build(); @@ -99,4 +99,4 @@ public class FailedNodeRoutingTests extends ESAllocationTestCase { assertThat(routingNode.numberOfShardsWithState(INITIALIZING), equalTo(1)); } } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java index e859c5811c3..5f4d6b5a8ba 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java @@ -67,7 +67,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding 2 nodes on same rack and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -158,7 +158,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -239,7 +239,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding single node and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); @@ -295,7 +295,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding {} nodes and performing rerouting", numberOfReplicas + 1); DiscoveryNodes.Builder nodeBuilder = DiscoveryNodes.builder(); @@ -351,7 +351,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -411,7 +411,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); @@ -502,7 +502,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); // add 4 nodes clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2")).put(newNode("node3")).put(newNode("node4"))).build(); @@ -548,7 +548,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); // add 4 nodes clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2")).put(newNode("node3")).put(newNode("node4"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java index 44437237dc9..0255e18e529 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java @@ -114,8 +114,8 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase { routingTableBuilder.addAsNew(metaData.index("idx")); RoutingTable routingTable = routingTableBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) - .metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING + .getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))) .build(); routingTable = service.reroute(clusterState, "reroute", false).routingTable(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java index 5a555621bec..ef0a589e50a 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java @@ -62,7 +62,7 @@ public class FilterRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding four nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -110,7 +110,7 @@ public class FilterRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -180,7 +180,7 @@ public class FilterRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes and performing rerouting"); DiscoveryNode node1 = newNode("node1", singletonMap("tag1", "value1")); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java index 874509d5cf1..79236ddd2b7 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java @@ -58,7 +58,7 @@ public class IndexBalanceTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).addAsNew(metaData.index("test1")).build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(3)); for (int i = 0; i < routingTable.index("test").shards().size(); i++) { @@ -188,7 +188,7 @@ public class IndexBalanceTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).addAsNew(metaData.index("test1")).build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(3)); for (int i = 0; i < routingTable.index("test").shards().size(); i++) { @@ -349,7 +349,7 @@ public class IndexBalanceTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(3)); for (int i = 0; i < routingTable.index("test").shards().size(); i++) { diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java index f76851cfef9..a5acb11ce4b 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.routing.allocation; import org.elasticsearch.Version; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.EmptyClusterInfoService; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -63,7 +64,7 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase { routingTableBuilder.addAsNew(metaData.index("idx")); RoutingTable routingTable = routingTableBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))) .build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java index 54df74db1f5..6dd4df59060 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java @@ -91,7 +91,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(5)); for (int i = 0; i < routingTable.index("test").shards().size(); i++) { @@ -209,7 +209,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase { } RoutingTable routingTable = rtBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.shardsWithState(UNASSIGNED).size(), equalTo(routingTable.allShards().size())); List nodes = new ArrayList<>(); int nodeIdx = 0; @@ -254,7 +254,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(5)); for (int i = 0; i < routingTable.index("test").shards().size(); i++) { @@ -331,7 +331,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase { .build()) ) .build(); - ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().put(newNode).put(oldNode1).put(oldNode2)).build(); @@ -360,7 +360,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase { (randomIntBetween(0, 3))) .build(); - ClusterState state = ClusterState.builder(ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(RoutingTable.builder().addAsRestore(metaData.index("test"), new RestoreSource(new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID())), diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java index 79c59b33b8e..3812a550169 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java @@ -62,7 +62,7 @@ public class PreferLocalPrimariesToRelocatingPrimariesTests extends ESAllocation .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("adding two nodes and performing rerouting till all are allocated"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java index 7067009a19e..decf0ed0ea3 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java @@ -59,7 +59,7 @@ public class PreferPrimaryAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("adding two nodes and performing rerouting till all are allocated"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java index 3c60a51f4fb..b5f1ab7235c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java @@ -55,7 +55,7 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); @@ -108,7 +108,7 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java index a636334b5d3..264a009650e 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java @@ -58,7 +58,7 @@ public class PrimaryNotRelocatedWhileBeingRecoveredTests extends ESAllocationTes .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java index 1f39706e4f4..7f62cced708 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java @@ -78,7 +78,7 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase { } RoutingTable routingTable = routingTableBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); int numIters = scaledRandomIntBetween(5, 15); int nodeIdCounter = 0; int atMostNodes = scaledRandomIntBetween(Math.max(1, maxNumReplicas), 15); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java index 035f6d3efff..0d743da39f3 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java @@ -87,7 +87,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(5)); for (int i = 0; i < routingTable.index("test").shards().size(); i++) { diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ReplicaAllocatedAfterPrimaryTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ReplicaAllocatedAfterPrimaryTests.java index e4b423c3f8f..aab3c8d6c2b 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ReplicaAllocatedAfterPrimaryTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ReplicaAllocatedAfterPrimaryTests.java @@ -57,7 +57,7 @@ public class ReplicaAllocatedAfterPrimaryTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(1)); assertThat(routingTable.index("test").shard(0).size(), equalTo(2)); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java index c23ab86b497..4283cb8475c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java @@ -58,7 +58,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).addAsNew(metaData.index("test1")).build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); RoutingNodes routingNodes = clusterState.getRoutingNodes(); logger.info("Adding three node and performing rerouting"); @@ -130,7 +130,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).addAsNew(metaData.index("test1")).build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding one node and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); @@ -222,7 +222,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding three node and performing rerouting"); clusterState = ClusterState.builder(clusterState) diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java index 9984890e8a4..3d0475ed137 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.routing.allocation; import org.elasticsearch.Version; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -56,7 +57,7 @@ public class SameShardRoutingTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData) .routingTable(routingTable).build(); logger.info("--> adding two nodes with the same host"); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardVersioningTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardVersioningTests.java index 1298bda30f9..29162aabb60 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardVersioningTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardVersioningTests.java @@ -54,7 +54,7 @@ public class ShardVersioningTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java index 26aa88a74a1..67fc93b600b 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java @@ -61,7 +61,7 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); routingTable = strategy.reroute(clusterState, "reroute").routingTable(); @@ -105,7 +105,7 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))).build(); routingTable = strategy.reroute(clusterState, "reroute").routingTable(); @@ -168,7 +168,7 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("Adding one node and reroute"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); routingTable = strategy.reroute(clusterState, "reroute").routingTable(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java index 4aaf05cc99f..ad9c0b8eef5 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java @@ -71,7 +71,7 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(1)); assertThat(routingTable.index("test").shard(0).size(), equalTo(1)); @@ -172,7 +172,7 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(1)); assertThat(routingTable.index("test").shard(0).size(), equalTo(1)); @@ -229,7 +229,7 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase { routingTableBuilder.addAsNew(metaData.index("test" + i)); } RoutingTable routingTable = routingTableBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.indicesRouting().size(), equalTo(numberOfIndices)); for (int i = 0; i < numberOfIndices; i++) { @@ -342,7 +342,7 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase { } RoutingTable routingTable = routingTableBuilder.build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.indicesRouting().size(), equalTo(numberOfIndices)); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java index 64a7b2abcf0..5c791b954f9 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java @@ -56,7 +56,7 @@ public class SingleShardOneReplicaRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(1)); assertThat(routingTable.index("test").shard(0).size(), equalTo(2)); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java index 5d01caaa899..16a11a9c150 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.TestShardRouting; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESAllocationTestCase; @@ -50,7 +51,7 @@ public class StartedShardsRoutingTests extends ESAllocationTestCase { .numberOfShards(3).numberOfReplicas(0) .build(); final Index index = indexMetaData.getIndex(); - ClusterState.Builder stateBuilder = ClusterState.builder(ClusterName.DEFAULT) + ClusterState.Builder stateBuilder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .nodes(DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2"))) .metaData(MetaData.builder().put(indexMetaData, false)); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java index fa1e9c34576..becd61e6eb2 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java @@ -67,7 +67,7 @@ public class TenShardsOneReplicaRoutingTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(10)); for (int i = 0; i < routingTable.index("test").shards().size(); i++) { diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java index ada5f4c19f8..0760367445d 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java @@ -63,7 +63,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase { RoutingTable routingTable = createRecoveryRoutingTable(metaData.index("test")); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start one node, do reroute, only 3 should initialize"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); @@ -122,7 +122,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase { RoutingTable routingTable = createRecoveryRoutingTable(metaData.index("test")); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start one node, do reroute, only 3 should initialize"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); @@ -190,7 +190,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase { RoutingTable routingTable = createRecoveryRoutingTable(metaData.index("test")); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start one node, do reroute, only 5 should initialize"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); @@ -253,7 +253,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase { RoutingTable routingTable = createRecoveryRoutingTable(metaData.index("test")); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("start one node, do reroute, only 1 should initialize"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode("node1"))).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java index 7d90e5ee2f2..47142062809 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java @@ -58,7 +58,7 @@ public class UpdateNumberOfReplicasTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); assertThat(routingTable.index("test").shards().size(), equalTo(1)); assertThat(routingTable.index("test").shard(0).size(), equalTo(2)); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java index 579e87150a7..87e5fd24a04 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation.decider; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterInfo; import org.elasticsearch.cluster.ClusterInfoService; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.DiskUsage; import org.elasticsearch.cluster.MockInternalClusterInfoService.DevNullClusterInfo; @@ -117,7 +118,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData) .routingTable(routingTable).build(); logger.info("--> adding two nodes"); @@ -318,7 +319,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData) .routingTable(routingTable).build(); logger.info("--> adding node1 and node2 node"); @@ -587,7 +588,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData) .routingTable(routingTable).build(); logger.info("--> adding node1"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -657,7 +658,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData) .routingTable(routingTable).build(); logger.info("--> adding node1"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -764,7 +765,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase { .addAsNew(metaData.index("test2")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData) + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData) .routingTable(routingTable).build(); logger.info("--> adding two nodes"); @@ -853,7 +854,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase { MASTER_DATA_ROLES, Version.CURRENT); DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().put(discoveryNode1).put(discoveryNode2).build(); - ClusterState baseClusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState baseClusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(discoveryNodes) @@ -969,7 +970,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase { singleton(DiscoveryNode.Role.DATA), Version.CURRENT); DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().put(discoveryNode1).put(discoveryNode2).build(); - ClusterState baseClusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState baseClusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(discoveryNodes) diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java index 8966659e63c..be50c5f5331 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java @@ -119,7 +119,7 @@ public class DiskThresholdDeciderUnitTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() .put(node_0) @@ -183,7 +183,7 @@ public class DiskThresholdDeciderUnitTests extends ESAllocationTestCase { .addAsNew(indexMetaData) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -242,7 +242,7 @@ public class DiskThresholdDeciderUnitTests extends ESAllocationTestCase { RoutingTable.Builder routingTableBuilder = RoutingTable.builder(); routingTableBuilder.addAsNew(metaData.index("test")); routingTableBuilder.addAsNew(metaData.index("other")); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData).routingTable(routingTableBuilder.build()).build(); RoutingAllocation allocation = new RoutingAllocation(null, null, clusterState, info, 0, false); @@ -314,7 +314,7 @@ public class DiskThresholdDeciderUnitTests extends ESAllocationTestCase { routingTableBuilder.addAsNew(metaData.index("test")); routingTableBuilder.addAsNew(metaData.index("target")); routingTableBuilder.addAsNew(metaData.index("target2")); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData).routingTable(routingTableBuilder.build()).build(); AllocationService allocationService = createAllocationService(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java index f2260aecfcb..53932eef390 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java @@ -68,7 +68,7 @@ public class EnableAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -96,7 +96,7 @@ public class EnableAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -130,7 +130,7 @@ public class EnableAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("enabled")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding two nodes and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -175,7 +175,7 @@ public class EnableAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("always_disabled")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding one nodes and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() @@ -275,7 +275,7 @@ public class EnableAllocationTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); logger.info("--> adding one nodes and do rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() diff --git a/core/src/test/java/org/elasticsearch/cluster/serialization/ClusterSerializationTests.java b/core/src/test/java/org/elasticsearch/cluster/serialization/ClusterSerializationTests.java index e7ca4f8382b..7b81d3ece27 100644 --- a/core/src/test/java/org/elasticsearch/cluster/serialization/ClusterSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/serialization/ClusterSerializationTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESAllocationTestCase; import static org.hamcrest.Matchers.equalTo; @@ -71,7 +72,8 @@ public class ClusterSerializationTests extends ESAllocationTestCase { DiscoveryNodes nodes = DiscoveryNodes.builder().put(newNode("node1")).put(newNode("node2")).put(newNode("node3")).build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).nodes(nodes).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes) + .metaData(metaData).routingTable(routingTable).build(); AllocationService strategy = createAllocationService(); RoutingTable source = strategy.reroute(clusterState, "reroute").routingTable(); diff --git a/core/src/test/java/org/elasticsearch/cluster/serialization/ClusterStateToStringTests.java b/core/src/test/java/org/elasticsearch/cluster/serialization/ClusterStateToStringTests.java index 3a30bd5c6aa..99cde60f086 100644 --- a/core/src/test/java/org/elasticsearch/cluster/serialization/ClusterStateToStringTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/serialization/ClusterStateToStringTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.cluster.serialization; import org.elasticsearch.Version; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; @@ -27,6 +28,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.allocation.AllocationService; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.test.ESAllocationTestCase; @@ -51,8 +53,8 @@ public class ClusterStateToStringTests extends ESAllocationTestCase { DiscoveryNodes nodes = DiscoveryNodes.builder().put(new DiscoveryNode("node_foo", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT)).localNodeId("node_foo").masterNodeId("node_foo").build(); - ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).nodes(nodes).metaData(metaData) - .routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes) + .metaData(metaData).routingTable(routingTable).build(); AllocationService strategy = createAllocationService(); clusterState = ClusterState.builder(clusterState).routingTable(strategy.reroute(clusterState, "reroute").routingTable()).build(); diff --git a/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java index dd71fa6a4a7..306eecf81b5 100644 --- a/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java @@ -108,9 +108,9 @@ public class ClusterServiceTests extends ESTestCase { } TimedClusterService createTimedClusterService(boolean makeMaster) throws InterruptedException { - TimedClusterService timedClusterService = new TimedClusterService(Settings.EMPTY, null, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - threadPool, new ClusterName("ClusterServiceTests")); + TimedClusterService timedClusterService = new TimedClusterService(Settings.builder().put("cluster.name", + "ClusterServiceTests").build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), + threadPool); timedClusterService.setLocalNode(new DiscoveryNode("node1", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT)); timedClusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) { @@ -941,9 +941,8 @@ public class ClusterServiceTests extends ESTestCase { public volatile Long currentTimeOverride = null; - public TimedClusterService(Settings settings, OperationRouting operationRouting, ClusterSettings clusterSettings, - ThreadPool threadPool, ClusterName clusterName) { - super(settings, operationRouting, clusterSettings, threadPool, clusterName); + public TimedClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) { + super(settings, clusterSettings, threadPool); } @Override diff --git a/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java b/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java index e9ec914d0dc..b8ebe9e6308 100644 --- a/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java @@ -37,6 +37,7 @@ import org.elasticsearch.cluster.routing.ShardsIterator; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; +import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESAllocationTestCase; @@ -237,7 +238,7 @@ public class RoutingIteratorTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); Map node1Attributes = new HashMap<>(); node1Attributes.put("rack_id", "rack_1"); @@ -291,7 +292,7 @@ public class RoutingIteratorTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() .put(newNode("fred", "node1", singletonMap("disk", "ebs"))) @@ -365,7 +366,7 @@ public class RoutingIteratorTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() .put(newNode("node1")) @@ -381,7 +382,8 @@ public class RoutingIteratorTests extends ESAllocationTestCase { routingTable = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)).routingTable(); clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build(); - OperationRouting operationRouting = new OperationRouting(Settings.Builder.EMPTY_SETTINGS, new AwarenessAllocationDecider()); + OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, + ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); GroupShardsIterator shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_shards:0"); assertThat(shardIterators.size(), equalTo(1)); @@ -426,7 +428,8 @@ public class RoutingIteratorTests extends ESAllocationTestCase { .put("cluster.routing.allocation.node_concurrent_recoveries", 10) .build()); - OperationRouting operationRouting = new OperationRouting(Settings.Builder.EMPTY_SETTINGS, new AwarenessAllocationDecider()); + OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, + ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); MetaData metaData = MetaData.builder() .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(2)) @@ -436,7 +439,7 @@ public class RoutingIteratorTests extends ESAllocationTestCase { .addAsNew(metaData.index("test")) .build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build(); + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() .put(newNode("node1")) diff --git a/core/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java b/core/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java index ea81e958342..90a3a2e8c1e 100644 --- a/core/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java @@ -142,8 +142,7 @@ public class ZenFaultDetectionTests extends ESTestCase { .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), singleton(TransportLivenessAction.NAME)) .build(), new LocalTransport(settings, threadPool, version, namedWriteableRegistry, circuitBreakerService), - threadPool, - ClusterName.DEFAULT); + threadPool); transportService.start(); transportService.acceptIncomingRequests(); return transportService; @@ -221,13 +220,15 @@ public class ZenFaultDetectionTests extends ESTestCase { public void testMasterFaultDetectionConnectOnDisconnect() throws InterruptedException { Settings.Builder settings = Settings.builder(); boolean shouldRetry = randomBoolean(); + ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20)); + // make sure we don't ping settings.put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry) - .put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m"); - ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20)); + .put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").put("cluster.name", clusterName.value()); + final ClusterState state = ClusterState.builder(clusterName).nodes(buildNodesForA(false)).build(); setState(clusterServiceA, state); - MasterFaultDetection masterFD = new MasterFaultDetection(settings.build(), threadPool, serviceA, clusterName, + MasterFaultDetection masterFD = new MasterFaultDetection(settings.build(), threadPool, serviceA, clusterServiceA); masterFD.start(nodeB, "test"); @@ -258,10 +259,11 @@ public class ZenFaultDetectionTests extends ESTestCase { public void testMasterFaultDetectionNotSizeLimited() throws InterruptedException { Settings.Builder settings = Settings.builder(); boolean shouldRetry = randomBoolean(); + ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20)); settings .put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry) - .put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "1s"); - ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20)); + .put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "1s") + .put("cluster.name", clusterName.value()); final ClusterState stateNodeA = ClusterState.builder(clusterName).nodes(buildNodesForA(false)).build(); setState(clusterServiceA, stateNodeA); @@ -273,14 +275,14 @@ public class ZenFaultDetectionTests extends ESTestCase { serviceA.addTracer(pingProbeA); serviceB.addTracer(pingProbeB); - MasterFaultDetection masterFDNodeA = new MasterFaultDetection(settings.build(), threadPool, serviceA, clusterName, + MasterFaultDetection masterFDNodeA = new MasterFaultDetection(settings.build(), threadPool, serviceA, clusterServiceA); masterFDNodeA.start(nodeB, "test"); final ClusterState stateNodeB = ClusterState.builder(clusterName).nodes(buildNodesForB(true)).build(); setState(clusterServiceB, stateNodeB); - MasterFaultDetection masterFDNodeB = new MasterFaultDetection(settings.build(), threadPool, serviceB, clusterName, + MasterFaultDetection masterFDNodeB = new MasterFaultDetection(settings.build(), threadPool, serviceB, clusterServiceB); masterFDNodeB.start(nodeB, "test"); diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ZenPingTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/ZenPingTests.java index 90b31ff3342..8aa5114c387 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/ZenPingTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/ZenPingTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.discovery.zen; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.test.ESTestCase; @@ -51,7 +52,8 @@ public class ZenPingTests extends ESTestCase { masterNode = nodes[randomInt(nodes.length - 1)]; } boolean hasJoinedOnce = randomBoolean(); - ZenPing.PingResponse ping = new ZenPing.PingResponse(nodes[node], masterNode, ClusterName.DEFAULT, hasJoinedOnce); + ZenPing.PingResponse ping = new ZenPing.PingResponse(nodes[node], masterNode, ClusterName.CLUSTER_NAME_SETTING. + getDefault(Settings.EMPTY), hasJoinedOnce); if (rarely()) { // ignore some pings continue; diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java b/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java index 2845e6a5bf0..11816512583 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java @@ -56,33 +56,39 @@ import static org.hamcrest.Matchers.greaterThan; public class UnicastZenPingIT extends ESTestCase { public void testSimplePings() throws InterruptedException { - Settings settings = Settings.EMPTY; int startPort = 11000 + randomIntBetween(0, 1000); int endPort = startPort + 10; - settings = Settings.builder().put(settings).put(TransportSettings.PORT.getKey(), startPort + "-" + endPort).build(); + Settings settings = Settings.builder() + .put("cluster.name", "test") + .put(TransportSettings.PORT.getKey(), startPort + "-" + endPort).build(); + + Settings settingsMismatch = Settings.builder().put(settings) + .put("cluster.name", "mismatch") + .put(TransportSettings.PORT.getKey(), startPort + "-" + endPort).build(); ThreadPool threadPool = new TestThreadPool(getClass().getName()); - ClusterName test = new ClusterName("test"); - ClusterName mismatch = new ClusterName("mismatch"); NetworkService networkService = new NetworkService(settings); ElectMasterService electMasterService = new ElectMasterService(settings, Version.CURRENT); - NetworkHandle handleA = startServices(settings, threadPool, networkService, "UZP_A", test, Version.CURRENT); - NetworkHandle handleB = startServices(settings, threadPool, networkService, "UZP_B", test, Version.CURRENT); - NetworkHandle handleC = startServices(settings, threadPool, networkService, "UZP_C", new ClusterName("mismatch"), Version.CURRENT); + NetworkHandle handleA = startServices(settings, threadPool, networkService, "UZP_A", Version.CURRENT); + NetworkHandle handleB = startServices(settings, threadPool, networkService, "UZP_B", Version.CURRENT); + NetworkHandle handleC = startServices(settingsMismatch, threadPool, networkService, "UZP_C", Version.CURRENT); // just fake that no versions are compatible with this node Version previousVersion = VersionUtils.getPreviousVersion(Version.CURRENT.minimumCompatibilityVersion()); Version versionD = VersionUtils.randomVersionBetween(random(), previousVersion.minimumCompatibilityVersion(), previousVersion); - NetworkHandle handleD = startServices(settings, threadPool, networkService, "UZP_D", test, versionD); + NetworkHandle handleD = startServices(settingsMismatch, threadPool, networkService, "UZP_D", versionD); - Settings hostsSettings = Settings.builder().putArray("discovery.zen.ping.unicast.hosts", + Settings hostsSettings = Settings.builder() + .putArray("discovery.zen.ping.unicast.hosts", NetworkAddress.format(new InetSocketAddress(handleA.address.address().getAddress(), handleA.address.address().getPort())), NetworkAddress.format(new InetSocketAddress(handleB.address.address().getAddress(), handleB.address.address().getPort())), NetworkAddress.format(new InetSocketAddress(handleC.address.address().getAddress(), handleC.address.address().getPort())), NetworkAddress.format(new InetSocketAddress(handleD.address.address().getAddress(), handleD.address.address().getPort()))) + .put("cluster.name", "test") .build(); - UnicastZenPing zenPingA = new UnicastZenPing(hostsSettings, threadPool, handleA.transportService, test, Version.CURRENT, electMasterService, null); + Settings hostsSettingsMismatch = Settings.builder().put(hostsSettings).put(settingsMismatch).build(); + UnicastZenPing zenPingA = new UnicastZenPing(hostsSettings, threadPool, handleA.transportService, Version.CURRENT, electMasterService, null); zenPingA.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { @@ -96,7 +102,7 @@ public class UnicastZenPingIT extends ESTestCase { }); zenPingA.start(); - UnicastZenPing zenPingB = new UnicastZenPing(hostsSettings, threadPool, handleB.transportService, test, Version.CURRENT, electMasterService, null); + UnicastZenPing zenPingB = new UnicastZenPing(hostsSettings, threadPool, handleB.transportService, Version.CURRENT, electMasterService, null); zenPingB.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { @@ -110,7 +116,7 @@ public class UnicastZenPingIT extends ESTestCase { }); zenPingB.start(); - UnicastZenPing zenPingC = new UnicastZenPing(hostsSettings, threadPool, handleC.transportService, mismatch, versionD, electMasterService, null); + UnicastZenPing zenPingC = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleC.transportService, versionD, electMasterService, null); zenPingC.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { @@ -124,7 +130,7 @@ public class UnicastZenPingIT extends ESTestCase { }); zenPingC.start(); - UnicastZenPing zenPingD = new UnicastZenPing(hostsSettings, threadPool, handleD.transportService, mismatch, Version.CURRENT, electMasterService, null); + UnicastZenPing zenPingD = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleD.transportService, Version.CURRENT, electMasterService, null); zenPingD.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { @@ -140,7 +146,7 @@ public class UnicastZenPingIT extends ESTestCase { try { logger.info("ping from UZP_A"); - ZenPing.PingResponse[] pingResponses = zenPingA.pingAndWait(TimeValue.timeValueSeconds(10)); + ZenPing.PingResponse[] pingResponses = zenPingA.pingAndWait(TimeValue.timeValueSeconds(1)); assertThat(pingResponses.length, equalTo(1)); assertThat(pingResponses[0].node().getId(), equalTo("UZP_B")); assertTrue(pingResponses[0].hasJoinedOnce()); @@ -148,19 +154,19 @@ public class UnicastZenPingIT extends ESTestCase { // ping again, this time from B, logger.info("ping from UZP_B"); - pingResponses = zenPingB.pingAndWait(TimeValue.timeValueSeconds(10)); + pingResponses = zenPingB.pingAndWait(TimeValue.timeValueSeconds(1)); assertThat(pingResponses.length, equalTo(1)); assertThat(pingResponses[0].node().getId(), equalTo("UZP_A")); assertFalse(pingResponses[0].hasJoinedOnce()); assertCounters(handleB, handleA, handleB, handleC, handleD); logger.info("ping from UZP_C"); - pingResponses = zenPingC.pingAndWait(TimeValue.timeValueSeconds(10)); + pingResponses = zenPingC.pingAndWait(TimeValue.timeValueSeconds(1)); assertThat(pingResponses.length, equalTo(0)); assertCounters(handleC, handleA, handleB, handleC, handleD); logger.info("ping from UZP_D"); - pingResponses = zenPingD.pingAndWait(TimeValue.timeValueSeconds(10)); + pingResponses = zenPingD.pingAndWait(TimeValue.timeValueSeconds(1)); assertThat(pingResponses.length, equalTo(0)); assertCounters(handleD, handleA, handleB, handleC, handleD); } finally { @@ -185,9 +191,9 @@ public class UnicastZenPingIT extends ESTestCase { } } - private NetworkHandle startServices(Settings settings, ThreadPool threadPool, NetworkService networkService, String nodeId, ClusterName clusterName, Version version) { + private NetworkHandle startServices(Settings settings, ThreadPool threadPool, NetworkService networkService, String nodeId, Version version) { NettyTransport transport = new NettyTransport(settings, threadPool, networkService, BigArrays.NON_RECYCLING_INSTANCE, version, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); - final TransportService transportService = new TransportService(transport, threadPool, clusterName); + final TransportService transportService = new TransportService(settings, transport, threadPool); transportService.start(); transportService.acceptIncomingRequests(); ConcurrentMap counters = new ConcurrentHashMap<>(); diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/publish/PendingClusterStatesQueueTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/publish/PendingClusterStatesQueueTests.java index 9c90e8de900..ab9aed6ba44 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/publish/PendingClusterStatesQueueTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/publish/PendingClusterStatesQueueTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.discovery.zen.publish.PendingClusterStatesQueue.ClusterStateContext; import org.elasticsearch.test.ESTestCase; @@ -235,7 +236,7 @@ public class PendingClusterStatesQueueTests extends ESTestCase { int masterIndex = randomInt(masters.length - 1); ClusterState state = lastClusterStatePerMaster[masterIndex]; if (state == null) { - state = ClusterState.builder(ClusterName.DEFAULT).nodes(DiscoveryNodes.builder() + state = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(DiscoveryNodes.builder() .put(new DiscoveryNode(masters[masterIndex], DummyTransportAddress.INSTANCE, emptyMap(), emptySet(),Version.CURRENT)).masterNodeId(masters[masterIndex]).build() ).build(); diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java index 7cc319c8579..ed09efaaada 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java @@ -85,7 +85,7 @@ import static org.hamcrest.Matchers.nullValue; @TestLogging("discovery.zen.publish:TRACE") public class PublishClusterStateActionTests extends ESTestCase { - private static final ClusterName CLUSTER_NAME = ClusterName.DEFAULT; + private static final ClusterName CLUSTER_NAME = ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY); protected ThreadPool threadPool; protected Map nodes = new HashMap<>(); @@ -233,7 +233,7 @@ public class PublishClusterStateActionTests extends ESTestCase { } protected MockTransportService buildTransportService(Settings settings, Version version) { - MockTransportService transportService = MockTransportService.local(Settings.EMPTY, version, threadPool, CLUSTER_NAME); + MockTransportService transportService = MockTransportService.local(Settings.EMPTY, version, threadPool); transportService.start(); transportService.acceptIncomingRequests(); return transportService; diff --git a/core/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java b/core/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java index b7d8a916315..f41b55a5ea5 100644 --- a/core/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java @@ -72,7 +72,7 @@ public class GatewayMetaStateTests extends ESAllocationTestCase { .build(); // assign all shards - ClusterState init = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState init = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaDataOldClusterState) .routingTable(routingTableOldClusterState) .nodes(generateDiscoveryNodes(masterEligible)) @@ -129,7 +129,7 @@ public class GatewayMetaStateTests extends ESAllocationTestCase { .build(); // assign all shards - ClusterState init = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState init = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaDataIndexCreated) .routingTable(routingTableIndexCreated) .nodes(generateDiscoveryNodes(masterEligible)) diff --git a/core/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java b/core/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java index 3a3f5f67e77..4f65c5fafdd 100644 --- a/core/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java @@ -33,9 +33,9 @@ import java.io.IOException; public class GatewayServiceTests extends ESTestCase { private GatewayService createService(Settings.Builder settings) { - ClusterService clusterService = new ClusterService(Settings.EMPTY, null, + ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "GatewayServiceTests").build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - null, new ClusterName("ClusterServiceTests")); + null); return new GatewayService(Settings.builder() .put("http.enabled", "false") .put("discovery.type", "local") diff --git a/core/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java b/core/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java index 3e088f4f82e..96e360550af 100644 --- a/core/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java @@ -344,7 +344,7 @@ public class PrimaryShardAllocatorTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsRestore(metaData.index(shardId.getIndex()), new RestoreSource(snapshot, version, shardId.getIndexName())) .build(); - ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().put(node1).put(node2).put(node3)).build(); @@ -423,7 +423,7 @@ public class PrimaryShardAllocatorTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsRestore(metaData.index(shardId.getIndex()), new RestoreSource(new Snapshot("test", new SnapshotId("test", UUIDs.randomBase64UUID())), Version.CURRENT, shardId.getIndexName())) .build(); - ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().put(node1).put(node2).put(node3)).build(); @@ -441,7 +441,7 @@ public class PrimaryShardAllocatorTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsRecovery(metaData.index(shardId.getIndex())) .build(); - ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().put(node1).put(node2).put(node3)).build(); @@ -482,7 +482,7 @@ public class PrimaryShardAllocatorTests extends ESAllocationTestCase { RoutingTable routingTable = RoutingTable.builder() .addAsRecovery(metaData.index(shardId.getIndex())) .build(); - ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().put(node1).put(node2).put(node3)).build(); @@ -523,7 +523,7 @@ public class PrimaryShardAllocatorTests extends ESAllocationTestCase { } else { routingTableBuilder.addAsRecovery(metaData.index(shardId.getIndex())); } - ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTableBuilder.build()) .nodes(DiscoveryNodes.builder().put(node1).put(node2).put(node3)).build(); diff --git a/core/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/core/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index 38dc2f9e632..99d6c56c88d 100644 --- a/core/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -302,7 +302,7 @@ public class ReplicaShardAllocatorTests extends ESAllocationTestCase { .build()) ) .build(); - ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().put(node1).put(node2).put(node3)).build(); @@ -324,7 +324,7 @@ public class ReplicaShardAllocatorTests extends ESAllocationTestCase { .build()) ) .build(); - ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT) + ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metaData(metaData) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().put(node1).put(node2).put(node3)).build(); diff --git a/core/src/test/java/org/elasticsearch/http/HttpServerTests.java b/core/src/test/java/org/elasticsearch/http/HttpServerTests.java index 9f002afd2dc..32f9bbbd84c 100644 --- a/core/src/test/java/org/elasticsearch/http/HttpServerTests.java +++ b/core/src/test/java/org/elasticsearch/http/HttpServerTests.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.http; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.bytes.ByteBufferBytesReference; @@ -73,8 +72,8 @@ public class HttpServerTests extends ESTestCase { throw new IllegalArgumentException("test error"); }); - ClusterService clusterService = new ClusterService(Settings.EMPTY, null, - new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null, ClusterName.DEFAULT); + ClusterService clusterService = new ClusterService(Settings.EMPTY, + new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null); NodeService nodeService = new NodeService(Settings.EMPTY, null, null, null, null, null, null, null, null, null, clusterService, null); httpServer = new HttpServer(settings, httpServerTransport, restController, nodeService, circuitBreakerService); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java index 8960f9dfe6e..cc8b05819c6 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java @@ -77,7 +77,7 @@ public class DynamicMappingDisabledTests extends ESSingleNodeTestCase { clusterService = createClusterService(THREAD_POOL); transport = new LocalTransport(settings, THREAD_POOL, Version.CURRENT, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); - transportService = new TransportService(transport, THREAD_POOL, clusterService.state().getClusterName()); + transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL); indicesService = getInstanceFromNode(IndicesService.class); shardStateAction = new ShardStateAction(settings, clusterService, transportService, null, null, THREAD_POOL); actionFilters = new ActionFilters(Collections.emptySet()); diff --git a/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java b/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java index 84e83db6d1d..86d19ae1ea4 100644 --- a/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java +++ b/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java @@ -143,7 +143,7 @@ public class ClusterStateChanges { } // services - TransportService transportService = new TransportService(settings, transport, threadPool, null); + TransportService transportService = new TransportService(settings, transport, threadPool); MetaDataIndexUpgradeService metaDataIndexUpgradeService = new MetaDataIndexUpgradeService(settings, null, null) { // metaData upgrader should do nothing @Override diff --git a/core/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java b/core/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java index 8c63c001a1e..78ef13dde56 100644 --- a/core/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java +++ b/core/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java @@ -267,7 +267,7 @@ public class IndicesClusterStateServiceRandomUpdatesTests extends AbstractIndice final Executor executor = mock(Executor.class); when(threadPool.generic()).thenReturn(executor); final MockIndicesService indicesService = new MockIndicesService(); - final TransportService transportService = new TransportService(Settings.EMPTY, null, threadPool, null); + final TransportService transportService = new TransportService(Settings.EMPTY, null, threadPool); final ClusterService clusterService = mock(ClusterService.class); final RepositoriesService repositoriesService = new RepositoriesService(Settings.EMPTY, clusterService, transportService, null, null); diff --git a/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreTests.java b/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreTests.java index f197073033d..e558f0f2a12 100644 --- a/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreTests.java +++ b/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreTests.java @@ -88,7 +88,7 @@ public class IndicesStoreTests extends ESTestCase { public void before() { localNode = new DiscoveryNode("abc", new LocalTransportAddress("abc"), emptyMap(), emptySet(), Version.CURRENT); clusterService = createClusterService(threadPool); - indicesStore = new IndicesStore(Settings.EMPTY, null, clusterService, new TransportService(null, null, clusterService.state().getClusterName()), null); + indicesStore = new IndicesStore(Settings.EMPTY, null, clusterService, new TransportService(clusterService.getSettings(), null, null), null); } @After diff --git a/core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java b/core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java index e7101869692..fd332321618 100644 --- a/core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java +++ b/core/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java @@ -153,8 +153,8 @@ public class SimpleMgetIT extends ESIntegTestCase { .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, between(2, DEFAULT_MAX_NUM_SHARDS)))); ensureYellow(); - final String id = routingKeyForShard("test", "test", 0); - final String routingOtherShard = routingKeyForShard("test", "test", 1); + final String id = routingKeyForShard("test", 0); + final String routingOtherShard = routingKeyForShard("test", 1); client().prepareIndex("test", "test", id).setRefreshPolicy(IMMEDIATE).setRouting(routingOtherShard) .setSource(jsonBuilder().startObject().field("foo", "bar").endObject()) diff --git a/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java index 87abc20a0de..226f6eae958 100644 --- a/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java +++ b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java @@ -68,13 +68,6 @@ public class InternalSettingsPreparerTests extends ESTestCase { assertTrue(configDir, configDir.startsWith(home)); } - public void testClusterNameDefault() { - Settings settings = InternalSettingsPreparer.prepareSettings(Settings.EMPTY); - assertEquals(ClusterName.DEFAULT.value(), settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey())); - settings = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null).settings(); - assertEquals(ClusterName.DEFAULT.value(), settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey())); - } - public void testReplacePromptPlaceholders() { MockTerminal terminal = new MockTerminal(); terminal.addTextInput("text"); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTestCase.java index a3723428874..fbd69755f24 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTestCase.java @@ -69,8 +69,8 @@ public abstract class ShardSizeTestCase extends ESIntegTestCase { List docs = new ArrayList<>(); - routing1 = routingKeyForShard("idx", "type", 0); - routing2 = routingKeyForShard("idx", "type", 1); + routing1 = routingKeyForShard("idx", 0); + routing2 = routingKeyForShard("idx", 1); docs.addAll(indexDoc(routing1, "1", 5)); docs.addAll(indexDoc(routing1, "2", 4)); diff --git a/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java b/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java index 68c4c76d7e8..4fa99b3b80c 100644 --- a/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java +++ b/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java @@ -66,7 +66,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { protected DiscoveryNode nodeB; protected MockTransportService serviceB; - protected abstract MockTransportService build(Settings settings, Version version, ClusterName clusterName); + protected abstract MockTransportService build(Settings settings, Version version); @Override @Before @@ -79,8 +79,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { .put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "") .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING") .build(), - version0, - ClusterName.DEFAULT); + version0); serviceA.acceptIncomingRequests(); nodeA = new DiscoveryNode("TS_A", serviceA.boundAddress().publishAddress(), emptyMap(), emptySet(), version0); serviceB = build( @@ -89,8 +88,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { .put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "") .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING") .build(), - version1, - ClusterName.DEFAULT); + version1); serviceB.acceptIncomingRequests(); nodeB = new DiscoveryNode("TS_B", serviceB.boundAddress().publishAddress(), emptyMap(), emptySet(), version1); @@ -1299,8 +1297,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { .put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "") .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING") .build(), - version0, - ClusterName.DEFAULT); + version0); AtomicBoolean requestProcessed = new AtomicBoolean(); service.registerRequestHandler("action", TestRequest::new, ThreadPool.Names.SAME, (request, channel) -> { diff --git a/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java b/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java index 3c382c39509..95ec6dad9bd 100644 --- a/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java +++ b/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java @@ -69,7 +69,7 @@ public class NettySizeHeaderFrameDecoderTests extends ESTestCase { nettyTransport = new NettyTransport(settings, threadPool, networkService, bigArrays, Version.CURRENT, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); nettyTransport.start(); - TransportService transportService = new TransportService(nettyTransport, threadPool, ClusterName.DEFAULT); + TransportService transportService = new TransportService(settings, nettyTransport, threadPool); nettyTransport.transportServiceAdapter(transportService.createAdapter()); TransportAddress[] boundAddresses = nettyTransport.boundAddress().boundAddresses(); diff --git a/core/src/test/java/org/elasticsearch/transport/NettyTransportServiceHandshakeTests.java b/core/src/test/java/org/elasticsearch/transport/NettyTransportServiceHandshakeTests.java index a111911e994..2213d7eb4cf 100644 --- a/core/src/test/java/org/elasticsearch/transport/NettyTransportServiceHandshakeTests.java +++ b/core/src/test/java/org/elasticsearch/transport/NettyTransportServiceHandshakeTests.java @@ -57,7 +57,7 @@ public class NettyTransportServiceHandshakeTests extends ESTestCase { private List transportServices = new ArrayList<>(); - private NetworkHandle startServices(String nodeNameAndId, Settings settings, Version version, ClusterName clusterName) { + private NetworkHandle startServices(String nodeNameAndId, Settings settings, Version version) { NettyTransport transport = new NettyTransport( settings, @@ -67,7 +67,7 @@ public class NettyTransportServiceHandshakeTests extends ESTestCase { Version.CURRENT, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); - TransportService transportService = new MockTransportService(settings, transport, threadPool, clusterName); + TransportService transportService = new MockTransportService(settings, transport, threadPool); transportService.start(); transportService.acceptIncomingRequests(); DiscoveryNode node = @@ -99,17 +99,14 @@ public class NettyTransportServiceHandshakeTests extends ESTestCase { } public void testConnectToNodeLight() { - Settings settings = Settings.EMPTY; + Settings settings = Settings.builder().put("cluster.name", "test").build(); - ClusterName test = new ClusterName("test"); - - NetworkHandle handleA = startServices("TS_A", settings, Version.CURRENT, test); + NetworkHandle handleA = startServices("TS_A", settings, Version.CURRENT); NetworkHandle handleB = startServices( "TS_B", settings, - VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT), - test); + VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT)); DiscoveryNode discoveryNode = new DiscoveryNode( "", handleB.discoveryNode.getAddress(), @@ -127,10 +124,9 @@ public class NettyTransportServiceHandshakeTests extends ESTestCase { } public void testMismatchedClusterName() { - Settings settings = Settings.EMPTY; - NetworkHandle handleA = startServices("TS_A", settings, Version.CURRENT, new ClusterName("a")); - NetworkHandle handleB = startServices("TS_B", settings, Version.CURRENT, new ClusterName("b")); + NetworkHandle handleA = startServices("TS_A", Settings.builder().put("cluster.name", "a").build(), Version.CURRENT); + NetworkHandle handleB = startServices("TS_B", Settings.builder().put("cluster.name", "b").build(), Version.CURRENT); DiscoveryNode discoveryNode = new DiscoveryNode( "", handleB.discoveryNode.getAddress(), @@ -144,12 +140,10 @@ public class NettyTransportServiceHandshakeTests extends ESTestCase { } public void testIncompatibleVersions() { - Settings settings = Settings.EMPTY; - - ClusterName test = new ClusterName("test"); - NetworkHandle handleA = startServices("TS_A", settings, Version.CURRENT, test); + Settings settings = Settings.builder().put("cluster.name", "test").build(); + NetworkHandle handleA = startServices("TS_A", settings, Version.CURRENT); NetworkHandle handleB = - startServices("TS_B", settings, VersionUtils.getPreviousVersion(Version.CURRENT.minimumCompatibilityVersion()), test); + startServices("TS_B", settings, VersionUtils.getPreviousVersion(Version.CURRENT.minimumCompatibilityVersion())); DiscoveryNode discoveryNode = new DiscoveryNode( "", handleB.discoveryNode.getAddress(), @@ -163,15 +157,14 @@ public class NettyTransportServiceHandshakeTests extends ESTestCase { } public void testIgnoreMismatchedClusterName() { - Settings settings = Settings.EMPTY; + Settings settings = Settings.builder().put("cluster.name", "a").build(); - NetworkHandle handleA = startServices("TS_A", settings, Version.CURRENT, new ClusterName("a")); + NetworkHandle handleA = startServices("TS_A", settings, Version.CURRENT); NetworkHandle handleB = startServices( "TS_B", - settings, - VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT), - new ClusterName("b") + Settings.builder().put("cluster.name", "b").build(), + VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT) ); DiscoveryNode discoveryNode = new DiscoveryNode( "", diff --git a/core/src/test/java/org/elasticsearch/transport/TransportModuleTests.java b/core/src/test/java/org/elasticsearch/transport/TransportModuleTests.java index 4eb14014cfc..20413888281 100644 --- a/core/src/test/java/org/elasticsearch/transport/TransportModuleTests.java +++ b/core/src/test/java/org/elasticsearch/transport/TransportModuleTests.java @@ -44,8 +44,8 @@ public class TransportModuleTests extends ModuleTestCase { static class FakeTransportService extends TransportService { @Inject - public FakeTransportService(Settings settings, Transport transport, ThreadPool threadPool, ClusterName clusterName) { - super(settings, transport, threadPool, clusterName); + public FakeTransportService(Settings settings, Transport transport, ThreadPool threadPool) { + super(settings, transport, threadPool); } } } diff --git a/core/src/test/java/org/elasticsearch/transport/local/SimpleLocalTransportTests.java b/core/src/test/java/org/elasticsearch/transport/local/SimpleLocalTransportTests.java index 2907a0a6ca8..c4458b7883d 100644 --- a/core/src/test/java/org/elasticsearch/transport/local/SimpleLocalTransportTests.java +++ b/core/src/test/java/org/elasticsearch/transport/local/SimpleLocalTransportTests.java @@ -29,8 +29,8 @@ import org.elasticsearch.transport.AbstractSimpleTransportTestCase; public class SimpleLocalTransportTests extends AbstractSimpleTransportTestCase { @Override - protected MockTransportService build(Settings settings, Version version, ClusterName clusterName) { - MockTransportService transportService = MockTransportService.local(settings, version, threadPool, clusterName); + protected MockTransportService build(Settings settings, Version version) { + MockTransportService transportService = MockTransportService.local(settings, version, threadPool); transportService.start(); return transportService; } diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java index de156659082..a98a038f6fd 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java @@ -58,6 +58,7 @@ public class NettyScheduledPingTests extends ESTestCase { Settings settings = Settings.builder() .put(NettyTransport.PING_SCHEDULE.getKey(), "5ms") .put(TransportSettings.PORT.getKey(), 0) + .put("cluster.name", "test") .build(); CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService(); @@ -65,15 +66,14 @@ public class NettyScheduledPingTests extends ESTestCase { NamedWriteableRegistry registryA = new NamedWriteableRegistry(); final NettyTransport nettyA = new NettyTransport(settings, threadPool, new NetworkService(settings), BigArrays.NON_RECYCLING_INSTANCE, Version.CURRENT, registryA, circuitBreakerService); - ClusterName test = new ClusterName("test"); - MockTransportService serviceA = new MockTransportService(settings, nettyA, threadPool, test); + MockTransportService serviceA = new MockTransportService(settings, nettyA, threadPool); serviceA.start(); serviceA.acceptIncomingRequests(); NamedWriteableRegistry registryB = new NamedWriteableRegistry(); final NettyTransport nettyB = new NettyTransport(settings, threadPool, new NetworkService(settings), BigArrays.NON_RECYCLING_INSTANCE, Version.CURRENT, registryB, circuitBreakerService); - MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool, test); + MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool); serviceB.start(); serviceB.acceptIncomingRequests(); diff --git a/core/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java b/core/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java index dac416128e5..f3cfcc3bebe 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java @@ -40,9 +40,9 @@ import static org.hamcrest.Matchers.containsString; public class SimpleNettyTransportTests extends AbstractSimpleTransportTestCase { @Override - protected MockTransportService build(Settings settings, Version version, ClusterName clusterName) { + protected MockTransportService build(Settings settings, Version version) { settings = Settings.builder().put(settings).put(TransportSettings.PORT.getKey(), "0").build(); - MockTransportService transportService = MockTransportService.nettyFromThreadPool(settings, version, threadPool, clusterName); + MockTransportService transportService = MockTransportService.nettyFromThreadPool(settings, version, threadPool); transportService.start(); return transportService; } diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndicesRequestTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndicesRequestTests.java index 27bb7fdc23f..c0751fe99e2 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndicesRequestTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndicesRequestTests.java @@ -719,8 +719,8 @@ public class IndicesRequestTests extends ESIntegTestCase { private final Map> requests = new HashMap<>(); @Inject - public InterceptingTransportService(Settings settings, Transport transport, ThreadPool threadPool, ClusterName clusterName) { - super(settings, transport, threadPool, clusterName); + public InterceptingTransportService(Settings settings, Transport transport, ThreadPool threadPool) { + super(settings, transport, threadPool); } synchronized List consumeRequests(String action) { diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportRethrottleAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportRethrottleAction.java index b716050c036..2990461c0a9 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportRethrottleAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportRethrottleAction.java @@ -39,9 +39,9 @@ import java.util.List; public class TransportRethrottleAction extends TransportTasksAction { @Inject - public TransportRethrottleAction(Settings settings, ClusterName clusterName, ThreadPool threadPool, ClusterService clusterService, + public TransportRethrottleAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, RethrottleAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters, + super(settings, RethrottleAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver, RethrottleRequest::new, ListTasksResponse::new, ThreadPool.Names.MANAGEMENT); } diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java index 956732113c1..319222caa7e 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java @@ -67,7 +67,7 @@ public class Ec2DiscoveryTests extends ESTestCase { @Before public void createTransportService() { - transportService = MockTransportService.local(Settings.EMPTY, Version.CURRENT, threadPool, ClusterName.DEFAULT); + transportService = MockTransportService.local(Settings.EMPTY, Version.CURRENT, threadPool); } protected List buildDynamicNodes(Settings nodeSettings, int nodes) { diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java index 78d96fd0163..e1041360b1f 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java @@ -95,7 +95,7 @@ public class GceDiscoveryTests extends ESTestCase { @Before public void createTransportService() { - transportService = MockTransportService.local(Settings.EMPTY, Version.CURRENT, threadPool, ClusterName.DEFAULT); + transportService = MockTransportService.local(Settings.EMPTY, Version.CURRENT, threadPool); } @Before diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java b/test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java index 3bb77d34f8d..128b0d0e315 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java @@ -81,7 +81,7 @@ public class MockInternalClusterInfoService extends InternalClusterInfoService { TransportIndicesStatsAction transportIndicesStatsAction, ClusterService clusterService, ThreadPool threadPool) { super(settings, clusterSettings, transportNodesStatsAction, transportIndicesStatsAction, clusterService, threadPool); - this.clusterName = ClusterName.clusterNameFromSettings(settings); + this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); stats[0] = makeStats("node_t1", new DiskUsage("node_t1", "n1", "/dev/null", 100, 100)); stats[1] = makeStats("node_t2", new DiskUsage("node_t2", "n2", "/dev/null", 100, 100)); stats[2] = makeStats("node_t3", new DiskUsage("node_t3", "n3", "/dev/null", 100, 100)); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java b/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java index 3e542231001..fe7ba74a327 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java @@ -43,9 +43,9 @@ import static junit.framework.TestCase.fail; public class ClusterServiceUtils { public static ClusterService createClusterService(ThreadPool threadPool) { - ClusterService clusterService = new ClusterService(Settings.EMPTY, null, + ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "ClusterServiceTests").build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - threadPool, new ClusterName("ClusterServiceTests")); + threadPool); clusterService.setLocalNode(new DiscoveryNode("node", DummyTransportAddress.INSTANCE, Collections.emptyMap(), new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())),Version.CURRENT)); clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) { diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index d892187fa94..095b1339800 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -80,7 +80,6 @@ import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.ByteSizeUnit; @@ -1980,8 +1979,8 @@ public abstract class ESIntegTestCase extends ESTestCase { * Compute a routing key that will route documents to the shard-th shard * of the provided index. */ - protected String routingKeyForShard(String index, String type, int shard) { - return internalCluster().routingKeyForShard(resolveIndex(index), type, shard, random()); + protected String routingKeyForShard(String index, int shard) { + return internalCluster().routingKeyForShard(resolveIndex(index), shard, random()); } /** diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java index f4d5b4dd482..4cf058a6a5d 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.env.Environment; @@ -43,7 +42,6 @@ import org.elasticsearch.index.IndexService; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; -import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.internal.SearchContext; diff --git a/test/framework/src/main/java/org/elasticsearch/test/ExternalNode.java b/test/framework/src/main/java/org/elasticsearch/test/ExternalNode.java index c08c2793eaa..8216f67cfed 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ExternalNode.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ExternalNode.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.node.Node; -import org.elasticsearch.node.internal.InternalSettingsPreparer; import java.io.Closeable; import java.io.IOException; diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 66f02c8a376..bb33ad17dde 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -1760,7 +1760,7 @@ public final class InternalTestCluster extends TestCluster { } } - synchronized String routingKeyForShard(Index index, String type, int shard, Random random) { + synchronized String routingKeyForShard(Index index, int shard, Random random) { assertThat(shard, greaterThanOrEqualTo(0)); assertThat(shard, greaterThanOrEqualTo(0)); for (NodeAndClient n : nodes.values()) { @@ -1770,7 +1770,7 @@ public final class InternalTestCluster extends TestCluster { IndexService indexService = indicesService.indexService(index); if (indexService != null) { assertThat(indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), greaterThan(shard)); - OperationRouting operationRouting = getInstanceFromNode(OperationRouting.class, node); + OperationRouting operationRouting = clusterService.operationRouting(); while (true) { String routing = RandomStrings.randomAsciiOfLength(random, 10); final int targetShard = operationRouting.indexShards(clusterService.state(), index.getName(), null, routing).shardId().getId(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java index eaa6faeca3f..110850e9a0f 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java @@ -94,29 +94,28 @@ public class MockTransportService extends TransportService { } } - public static MockTransportService local(Settings settings, Version version, ThreadPool threadPool, ClusterName clusterName) { + public static MockTransportService local(Settings settings, Version version, ThreadPool threadPool) { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); Transport transport = new LocalTransport(settings, threadPool, version, namedWriteableRegistry, new NoneCircuitBreakerService()); - return new MockTransportService(settings, transport, threadPool, clusterName); + return new MockTransportService(settings, transport, threadPool); } public static MockTransportService nettyFromThreadPool( Settings settings, Version version, - ThreadPool threadPool, - ClusterName clusterName) { + ThreadPool threadPool) { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); Transport transport = new NettyTransport(settings, threadPool, new NetworkService(settings), BigArrays.NON_RECYCLING_INSTANCE, version, namedWriteableRegistry, new NoneCircuitBreakerService()); - return new MockTransportService(Settings.EMPTY, transport, threadPool, clusterName); + return new MockTransportService(Settings.EMPTY, transport, threadPool); } private final Transport original; @Inject - public MockTransportService(Settings settings, Transport transport, ThreadPool threadPool, ClusterName clusterName) { - super(settings, new LookupTestTransport(transport), threadPool, clusterName); + public MockTransportService(Settings settings, Transport transport, ThreadPool threadPool) { + super(settings, new LookupTestTransport(transport), threadPool); this.original = transport; } From fb2a48d0f0fbdb58196557df24f148bb3316eba1 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 17 Jun 2016 17:14:01 +0200 Subject: [PATCH 33/87] Revert "Remove support for sorting terms aggregation by ascending count" This is delayed after alpha4 since Kibana relies on it. --- .../bucket/terms/InternalOrder.java | 19 +++- .../bucket/terms/InternalTerms.java | 2 +- .../aggregations/bucket/terms/Terms.java | 6 +- .../bucket/terms/TermsAggregationBuilder.java | 2 +- .../bucket/terms/TermsParser.java | 20 +--- .../aggregations/bucket/ShardSizeTermsIT.java | 24 ++--- .../bucket/TermsDocCountErrorIT.java | 93 +++++++++++++++++++ .../aggregations/bucket/TermsTests.java | 2 +- .../bucket/terms-aggregation.asciidoc | 13 +-- .../migrate_5_0/aggregations.asciidoc | 4 - .../messy/tests/DoubleTermsTests.java | 7 +- .../messy/tests/LongTermsTests.java | 7 +- .../messy/tests/MinDocCountTests.java | 48 ++++++++-- .../messy/tests/StringTermsTests.java | 7 +- .../test/search.aggregation/20_terms.yaml | 15 +-- 15 files changed, 194 insertions(+), 75 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalOrder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalOrder.java index 5ebeb6ee7fb..f3f87c09dca 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalOrder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalOrder.java @@ -46,8 +46,9 @@ import java.util.Objects; class InternalOrder extends Terms.Order { private static final byte COUNT_DESC_ID = 1; - private static final byte TERM_DESC_ID = 2; - private static final byte TERM_ASC_ID = 3; + private static final byte COUNT_ASC_ID = 2; + private static final byte TERM_DESC_ID = 3; + private static final byte TERM_ASC_ID = 4; /** * Order by the (higher) count of each term. @@ -59,6 +60,17 @@ class InternalOrder extends Terms.Order { } }); + /** + * Order by the (lower) count of each term. + */ + public static final InternalOrder COUNT_ASC = new InternalOrder(COUNT_ASC_ID, "_count", true, new Comparator() { + + @Override + public int compare(Terms.Bucket o1, Terms.Bucket o2) { + return Long.compare(o1.getDocCount(), o2.getDocCount()); + } + }); + /** * Order by the terms. */ @@ -81,7 +93,7 @@ class InternalOrder extends Terms.Order { } }); - public static boolean isCountOrder(Terms.Order order) { + public static boolean isCountDesc(Terms.Order order) { if (order == COUNT_DESC) { return true; } else if (order instanceof CompoundOrder) { @@ -336,6 +348,7 @@ class InternalOrder extends Terms.Order { byte id = in.readByte(); switch (id) { case COUNT_DESC_ID: return absoluteOrder ? new CompoundOrder(Collections.singletonList((Terms.Order) InternalOrder.COUNT_DESC)) : InternalOrder.COUNT_DESC; + case COUNT_ASC_ID: return absoluteOrder ? new CompoundOrder(Collections.singletonList((Terms.Order) InternalOrder.COUNT_ASC)) : InternalOrder.COUNT_ASC; case TERM_DESC_ID: return InternalOrder.TERM_DESC; case TERM_ASC_ID: return InternalOrder.TERM_ASC; case Aggregation.ID: diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTerms.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTerms.java index 5784066f85c..fcbd66dced6 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTerms.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTerms.java @@ -192,7 +192,7 @@ public abstract class InternalTerms otherOptions) throws IOException { - if (token == Token.VALUE_STRING) { + if (token == XContentParser.Token.START_OBJECT) { if (parseFieldMatcher.match(currentFieldName, TermsAggregationBuilder.ORDER_FIELD)) { - if ("_count".equals(parser.text())) { - otherOptions.put(TermsAggregationBuilder.ORDER_FIELD, - Collections.singletonList(new OrderElement(parser.text(), false))); - return true; - } - } - return false; - } else if (token == XContentParser.Token.START_OBJECT) { - if (parseFieldMatcher.match(currentFieldName, TermsAggregationBuilder.ORDER_FIELD)) { - otherOptions.put(TermsAggregationBuilder.ORDER_FIELD, - Collections.singletonList(parseOrderParam(aggregationName, parser))); + otherOptions.put(TermsAggregationBuilder.ORDER_FIELD, Collections.singletonList(parseOrderParam(aggregationName, parser))); return true; } } else if (token == XContentParser.Token.START_ARRAY) { @@ -127,10 +117,6 @@ public class TermsParser extends AbstractTermsParser { } else if (token == XContentParser.Token.VALUE_STRING) { String dir = parser.text(); if ("asc".equalsIgnoreCase(dir)) { - if ("_count".equals(orderKey)) { - throw new ParsingException(parser.getTokenLocation(), - "Sort by ascending _count is not supported in [" + aggregationName + "]."); - } orderAsc = true; } else if ("desc".equalsIgnoreCase(dir)) { orderAsc = false; @@ -181,7 +167,7 @@ public class TermsParser extends AbstractTermsParser { return Order.term(asc); } if ("_count".equals(key)) { - return Order.count(); + return Order.count(asc); } return Order.aggregation(key, asc); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTermsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTermsIT.java index 82b60289c75..ecc16b85f13 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTermsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ShardSizeTermsIT.java @@ -39,7 +39,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -62,7 +62,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3).shardSize(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -86,7 +86,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -110,7 +110,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type").setRouting(routing1) .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -156,7 +156,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -179,7 +179,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3).shardSize(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -202,7 +202,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -226,7 +226,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type").setRouting(routing1) .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -272,7 +272,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -295,7 +295,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3).shardSize(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -318,7 +318,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type") .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); @@ -341,7 +341,7 @@ public class ShardSizeTermsIT extends ShardSizeTestCase { SearchResponse response = client().prepareSearch("idx").setTypes("type").setRouting(routing1) .setQuery(matchAllQuery()) .addAggregation(terms("keys").field("key").size(3) - .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count())) + .collectMode(randomFrom(SubAggCollectionMode.values())).shardSize(5).order(Terms.Order.count(false))) .execute().actionGet(); Terms terms = response.getAggregations().get("keys"); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java index 00c73b42246..6bbe1dc22b2 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java @@ -271,6 +271,37 @@ public class TermsDocCountErrorIT extends ESIntegTestCase { assertNoDocCountErrorSingleResponse(size, testResponse); } + public void testStringValueFieldDocCountAsc() throws Exception { + int size = randomIntBetween(1, 20); + int shardSize = randomIntBetween(size, size * 2); + SearchResponse accurateResponse = client().prepareSearch("idx_single_shard").setTypes("type") + .addAggregation(terms("terms") + .executionHint(randomExecutionHint()) + .field(STRING_FIELD_NAME) + .showTermDocCountError(true) + .size(10000).shardSize(10000) + .order(Order.count(true)) + .collectMode(randomFrom(SubAggCollectionMode.values()))) + .execute().actionGet(); + + assertSearchResponse(accurateResponse); + + SearchResponse testResponse = client().prepareSearch("idx_single_shard").setTypes("type") + .addAggregation(terms("terms") + .executionHint(randomExecutionHint()) + .field(STRING_FIELD_NAME) + .showTermDocCountError(true) + .size(size) + .shardSize(shardSize) + .order(Order.count(true)) + .collectMode(randomFrom(SubAggCollectionMode.values()))) + .execute().actionGet(); + + assertSearchResponse(testResponse); + + assertUnboundedDocCountError(size, accurateResponse, testResponse); + } + public void testStringValueFieldTermSortAsc() throws Exception { int size = randomIntBetween(1, 20); int shardSize = randomIntBetween(size, size * 2); @@ -476,6 +507,37 @@ public class TermsDocCountErrorIT extends ESIntegTestCase { assertNoDocCountErrorSingleResponse(size, testResponse); } + public void testLongValueFieldDocCountAsc() throws Exception { + int size = randomIntBetween(1, 20); + int shardSize = randomIntBetween(size, size * 2); + SearchResponse accurateResponse = client().prepareSearch("idx_single_shard").setTypes("type") + .addAggregation(terms("terms") + .executionHint(randomExecutionHint()) + .field(LONG_FIELD_NAME) + .showTermDocCountError(true) + .size(10000).shardSize(10000) + .order(Order.count(true)) + .collectMode(randomFrom(SubAggCollectionMode.values()))) + .execute().actionGet(); + + assertSearchResponse(accurateResponse); + + SearchResponse testResponse = client().prepareSearch("idx_single_shard").setTypes("type") + .addAggregation(terms("terms") + .executionHint(randomExecutionHint()) + .field(LONG_FIELD_NAME) + .showTermDocCountError(true) + .size(size) + .shardSize(shardSize) + .order(Order.count(true)) + .collectMode(randomFrom(SubAggCollectionMode.values()))) + .execute().actionGet(); + + assertSearchResponse(testResponse); + + assertUnboundedDocCountError(size, accurateResponse, testResponse); + } + public void testLongValueFieldTermSortAsc() throws Exception { int size = randomIntBetween(1, 20); int shardSize = randomIntBetween(size, size * 2); @@ -681,6 +743,37 @@ public class TermsDocCountErrorIT extends ESIntegTestCase { assertNoDocCountErrorSingleResponse(size, testResponse); } + public void testDoubleValueFieldDocCountAsc() throws Exception { + int size = randomIntBetween(1, 20); + int shardSize = randomIntBetween(size, size * 2); + SearchResponse accurateResponse = client().prepareSearch("idx_single_shard").setTypes("type") + .addAggregation(terms("terms") + .executionHint(randomExecutionHint()) + .field(DOUBLE_FIELD_NAME) + .showTermDocCountError(true) + .size(10000).shardSize(10000) + .order(Order.count(true)) + .collectMode(randomFrom(SubAggCollectionMode.values()))) + .execute().actionGet(); + + assertSearchResponse(accurateResponse); + + SearchResponse testResponse = client().prepareSearch("idx_single_shard").setTypes("type") + .addAggregation(terms("terms") + .executionHint(randomExecutionHint()) + .field(DOUBLE_FIELD_NAME) + .showTermDocCountError(true) + .size(size) + .shardSize(shardSize) + .order(Order.count(true)) + .collectMode(randomFrom(SubAggCollectionMode.values()))) + .execute().actionGet(); + + assertSearchResponse(testResponse); + + assertUnboundedDocCountError(size, accurateResponse, testResponse); + } + public void testDoubleValueFieldTermSortAsc() throws Exception { int size = randomIntBetween(1, 20); int shardSize = randomIntBetween(size, size * 2); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java index 055258bb4cc..c8a14e82bf4 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java @@ -180,7 +180,7 @@ public class TermsTests extends BaseAggregationTestCase orders.add(Terms.Order.term(randomBoolean())); break; case 1: - orders.add(Terms.Order.count()); + orders.add(Terms.Order.count(randomBoolean())); break; case 2: orders.add(Terms.Order.aggregation(randomAsciiOfLengthBetween(3, 20), randomBoolean())); diff --git a/docs/reference/aggregations/bucket/terms-aggregation.asciidoc b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc index 30e3d649179..3c1f4ae860a 100644 --- a/docs/reference/aggregations/bucket/terms-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc @@ -239,7 +239,9 @@ determined and is given a value of -1 to indicate this. ==== Order The order of the buckets can be customized by setting the `order` parameter. By default, the buckets are ordered by -their `doc_count` descending: +their `doc_count` descending. It is also possible to change this behaviour as follows: + +Ordering the buckets by their `doc_count` in an ascending manner: [source,js] -------------------------------------------------- @@ -248,15 +250,12 @@ their `doc_count` descending: "genders" : { "terms" : { "field" : "gender", - "order" : "_count" <1> + "order" : { "_count" : "asc" } } } } } -------------------------------------------------- -<1> This is the default if the order is missing. - -It is also possible to change this behaviour as follows: Ordering the buckets alphabetically by their terms in an ascending manner: @@ -313,9 +312,7 @@ Ordering the buckets by multi value metrics sub-aggregation (identified by the a } -------------------------------------------------- -Ordering the buckets by their `doc_count` in an ascending manner is not supported. - -WARNING: Sorting by sub aggregation is discouraged as it increases the +WARNING: Sorting by ascending `_count` or by sub aggregation is discouraged as it increases the <> on document counts. It is fine when a single shard is queried, or when the field that is being aggregated was used as a routing key at index time: in these cases results will be accurate since shards have disjoint diff --git a/docs/reference/migration/migrate_5_0/aggregations.asciidoc b/docs/reference/migration/migrate_5_0/aggregations.asciidoc index 57afd44719b..d9227e91385 100644 --- a/docs/reference/migration/migrate_5_0/aggregations.asciidoc +++ b/docs/reference/migration/migrate_5_0/aggregations.asciidoc @@ -26,7 +26,3 @@ for `from` and `to` anymore. `size: 0` is no longer valid for the terms, significant terms and geohash grid aggregations. Instead a size should be explicitly specified with a number greater than zero. - -==== `order: {"count": "asc"}` on Terms - -The ability to sort the terms aggregation by ascending count has been removed. diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/DoubleTermsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/DoubleTermsTests.java index 5e1dec0402f..6ed77fffcc8 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/DoubleTermsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/DoubleTermsTests.java @@ -1048,6 +1048,11 @@ public class DoubleTermsTests extends AbstractTermsTestCase { assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("avg_l", false), Terms.Order.term(true)); } + public void testSingleValuedFieldOrderedByCountAscAndSingleValueSubAggregationAsc() throws Exception { + double[] expectedKeys = new double[] { 6, 7, 3, 4, 5, 1, 2 }; + assertMultiSortResponse(expectedKeys, Terms.Order.count(true), Terms.Order.aggregation("avg_l", true)); + } + public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscSingleValueSubAggregationAsc() throws Exception { double[] expectedKeys = new double[] { 6, 7, 3, 5, 4, 1, 2 }; assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("sum_d", true), Terms.Order.aggregation("avg_l", true)); @@ -1055,7 +1060,7 @@ public class DoubleTermsTests extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByThreeCriteria() throws Exception { double[] expectedKeys = new double[] { 2, 1, 4, 5, 3, 6, 7 }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); + assertMultiSortResponse(expectedKeys, Terms.Order.count(false), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); } public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscAsCompound() throws Exception { diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java index efc9833a33d..fa049429a3a 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/LongTermsTests.java @@ -1025,6 +1025,11 @@ public class LongTermsTests extends AbstractTermsTestCase { assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("avg_l", false), Terms.Order.term(true)); } + public void testSingleValuedFieldOrderedByCountAscAndSingleValueSubAggregationAsc() throws Exception { + long[] expectedKeys = new long[] { 6, 7, 3, 4, 5, 1, 2 }; + assertMultiSortResponse(expectedKeys, Terms.Order.count(true), Terms.Order.aggregation("avg_l", true)); + } + public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscSingleValueSubAggregationAsc() throws Exception { long[] expectedKeys = new long[] { 6, 7, 3, 5, 4, 1, 2 }; assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("sum_d", true), Terms.Order.aggregation("avg_l", true)); @@ -1032,7 +1037,7 @@ public class LongTermsTests extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByThreeCriteria() throws Exception { long[] expectedKeys = new long[] { 2, 1, 4, 5, 3, 6, 7 }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); + assertMultiSortResponse(expectedKeys, Terms.Order.count(false), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); } public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscAsCompound() throws Exception { diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/MinDocCountTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/MinDocCountTests.java index c24551ed588..662d4d2f30c 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/MinDocCountTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/MinDocCountTests.java @@ -173,20 +173,36 @@ public class MinDocCountTests extends AbstractTermsTestCase { testMinDocCountOnTerms("s", Script.YES, Terms.Order.term(false)); } + public void testStringCountAsc() throws Exception { + testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(true)); + } + + public void testStringScriptCountAsc() throws Exception { + testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(true)); + } + public void testStringCountDesc() throws Exception { - testMinDocCountOnTerms("s", Script.NO, Terms.Order.count()); + testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(false)); } public void testStringScriptCountDesc() throws Exception { - testMinDocCountOnTerms("s", Script.YES, Terms.Order.count()); + testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(false)); + } + + public void testStringCountAscWithInclude() throws Exception { + testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(true), ".*a.*", true); + } + + public void testStringScriptCountAscWithInclude() throws Exception { + testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(true), ".*a.*", true); } public void testStringCountDescWithInclude() throws Exception { - testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(), ".*a.*", true); + testMinDocCountOnTerms("s", Script.NO, Terms.Order.count(false), ".*a.*", true); } public void testStringScriptCountDescWithInclude() throws Exception { - testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(), ".*a.*", true); + testMinDocCountOnTerms("s", Script.YES, Terms.Order.count(false), ".*a.*", true); } public void testLongTermAsc() throws Exception { @@ -205,12 +221,20 @@ public class MinDocCountTests extends AbstractTermsTestCase { testMinDocCountOnTerms("l", Script.YES, Terms.Order.term(false)); } + public void testLongCountAsc() throws Exception { + testMinDocCountOnTerms("l", Script.NO, Terms.Order.count(true)); + } + + public void testLongScriptCountAsc() throws Exception { + testMinDocCountOnTerms("l", Script.YES, Terms.Order.count(true)); + } + public void testLongCountDesc() throws Exception { - testMinDocCountOnTerms("l", Script.NO, Terms.Order.count()); + testMinDocCountOnTerms("l", Script.NO, Terms.Order.count(false)); } public void testLongScriptCountDesc() throws Exception { - testMinDocCountOnTerms("l", Script.YES, Terms.Order.count()); + testMinDocCountOnTerms("l", Script.YES, Terms.Order.count(false)); } public void testDoubleTermAsc() throws Exception { @@ -229,12 +253,20 @@ public class MinDocCountTests extends AbstractTermsTestCase { testMinDocCountOnTerms("d", Script.YES, Terms.Order.term(false)); } + public void testDoubleCountAsc() throws Exception { + testMinDocCountOnTerms("d", Script.NO, Terms.Order.count(true)); + } + + public void testDoubleScriptCountAsc() throws Exception { + testMinDocCountOnTerms("d", Script.YES, Terms.Order.count(true)); + } + public void testDoubleCountDesc() throws Exception { - testMinDocCountOnTerms("d", Script.NO, Terms.Order.count()); + testMinDocCountOnTerms("d", Script.NO, Terms.Order.count(false)); } public void testDoubleScriptCountDesc() throws Exception { - testMinDocCountOnTerms("d", Script.YES, Terms.Order.count()); + testMinDocCountOnTerms("d", Script.YES, Terms.Order.count(false)); } private void testMinDocCountOnTerms(String field, Script script, Terms.Order order) throws Exception { diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java index a5825d23172..b098db154da 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/StringTermsTests.java @@ -1375,6 +1375,11 @@ public class StringTermsTests extends AbstractTermsTestCase { assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("avg_l", false), Terms.Order.term(true)); } + public void testSingleValuedFieldOrderedByCountAscAndSingleValueSubAggregationAsc() throws Exception { + String[] expectedKeys = new String[] { "val6", "val7", "val3", "val4", "val5", "val1", "val2" }; + assertMultiSortResponse(expectedKeys, Terms.Order.count(true), Terms.Order.aggregation("avg_l", true)); + } + public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscSingleValueSubAggregationAsc() throws Exception { String[] expectedKeys = new String[] { "val6", "val7", "val3", "val5", "val4", "val1", "val2" }; assertMultiSortResponse(expectedKeys, Terms.Order.aggregation("sum_d", true), Terms.Order.aggregation("avg_l", true)); @@ -1382,7 +1387,7 @@ public class StringTermsTests extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByThreeCriteria() throws Exception { String[] expectedKeys = new String[] { "val2", "val1", "val4", "val5", "val3", "val6", "val7" }; - assertMultiSortResponse(expectedKeys, Terms.Order.count(), Terms.Order.aggregation("sum_d", false), + assertMultiSortResponse(expectedKeys, Terms.Order.count(false), Terms.Order.aggregation("sum_d", false), Terms.Order.aggregation("avg_l", false)); } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yaml index c079e6b6f7e..c35e79e6cfe 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yaml @@ -350,17 +350,4 @@ setup: - match: { aggregations.date_terms.buckets.0.key_as_string: "2014-09-01T00:00:00.000Z" } - - match: { aggregations.date_terms.buckets.0.doc_count: 1 } - ---- -"Terms count order test": - - do: - catch: /Sort by ascending _count is not supported in/ - search: - body: { "size" : 0, "aggs" : { "count_order" : { "terms" : { "field" : "f1", "order": {"_count": "asc"} } } } } - - - do: - search: - body: { "size" : 0, "aggs" : { "count_order" : { "terms" : { "field" : "f1", "order": "_count" } } } } - - + - match: { aggregations.date_terms.buckets.0.doc_count: 1 } From 46b40f73b7697eeb84e542c2f1801a2f96501bdc Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Fri, 17 Jun 2016 17:32:38 +0200 Subject: [PATCH 34/87] Inline reroute with process of node join/master election (#18938) In the past, we had the semantics where the very first cluster state a node processed after joining could not contain shard assignment to it. This was to make sure the node cleans up local / stale shard copies before receiving new ones that might confuse it. Since then a lot of work in this area, most notably the introduction of allocation ids and #17270 . This means we don't have to be careful and just reroute in the same cluster state change where we process the join, keeping things simple and following the same pattern we have in other places. --- .../cluster/routing/RoutingService.java | 4 -- .../elasticsearch/discovery/Discovery.java | 4 +- .../discovery/local/LocalDiscovery.java | 24 ++++++------ .../discovery/zen/NodeJoinController.java | 39 +++++++------------ .../discovery/zen/ZenDiscovery.java | 17 ++++---- .../java/org/elasticsearch/node/Node.java | 3 +- .../zen/NodeJoinControllerTests.java | 30 ++++++-------- .../org/elasticsearch/test/NoopDiscovery.java | 4 +- 8 files changed, 49 insertions(+), 76 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java index 78e7e15d389..d6ec9048688 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java @@ -72,10 +72,6 @@ public class RoutingService extends AbstractLifecycleComponent { protected void doClose() { } - public AllocationService getAllocationService() { - return this.allocationService; - } - /** * Initiates a reroute. */ diff --git a/core/src/main/java/org/elasticsearch/discovery/Discovery.java b/core/src/main/java/org/elasticsearch/discovery/Discovery.java index 778e2d15053..dabd45e36dd 100644 --- a/core/src/main/java/org/elasticsearch/discovery/Discovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/Discovery.java @@ -22,7 +22,7 @@ package org.elasticsearch.discovery; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.RoutingService; +import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.io.stream.StreamInput; @@ -44,7 +44,7 @@ public interface Discovery extends LifecycleComponent { * Another hack to solve dep injection problem..., note, this will be called before * any start is called. */ - void setRoutingService(RoutingService routingService); + void setAllocationService(AllocationService allocationService); /** * Publish all the changes to the cluster from the master (can be called just by the master). The publish diff --git a/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java index 696eb8812c9..ec9158c5932 100644 --- a/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java @@ -28,7 +28,7 @@ import org.elasticsearch.cluster.IncompatibleClusterStateVersionException; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.RoutingService; +import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.component.AbstractLifecycleComponent; @@ -61,7 +61,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent implem private static final LocalDiscovery[] NO_MEMBERS = new LocalDiscovery[0]; private final ClusterService clusterService; - private RoutingService routingService; + private AllocationService allocationService; private final ClusterName clusterName; private final DiscoverySettings discoverySettings; @@ -83,8 +83,8 @@ public class LocalDiscovery extends AbstractLifecycleComponent implem } @Override - public void setRoutingService(RoutingService routingService) { - this.routingService = routingService; + public void setAllocationService(AllocationService allocationService) { + this.allocationService = allocationService; } @Override @@ -156,7 +156,12 @@ public class LocalDiscovery extends AbstractLifecycleComponent implem nodesBuilder.put(discovery.localNode()); } nodesBuilder.localNodeId(master.localNode().getId()).masterNodeId(master.localNode().getId()); - return ClusterState.builder(currentState).nodes(nodesBuilder).build(); + currentState = ClusterState.builder(currentState).nodes(nodesBuilder).build(); + RoutingAllocation.Result result = master.allocationService.reroute(currentState, "node_add"); + if (result.changed()) { + currentState = ClusterState.builder(currentState).routingResult(result).build(); + } + return currentState; } @Override @@ -164,13 +169,6 @@ public class LocalDiscovery extends AbstractLifecycleComponent implem logger.error("unexpected failure during [{}]", t, source); } - @Override - public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { - // we reroute not in the same cluster state update since in certain areas we rely on - // the node to be in the cluster state (sampled from ClusterService#state) to be there, also - // shard transitions need to better be handled in such cases - master.routingService.reroute("post_node_add"); - } }); } } // else, no master node, the next node that will start will fill things in... @@ -226,7 +224,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent implem } // reroute here, so we eagerly remove dead nodes from the routing ClusterState updatedState = ClusterState.builder(currentState).nodes(newNodes).build(); - RoutingAllocation.Result routingResult = master.routingService.getAllocationService().reroute( + RoutingAllocation.Result routingResult = master.allocationService.reroute( ClusterState.builder(updatedState).build(), "elected as master"); return ClusterState.builder(updatedState).routingResult(routingResult).build(); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java b/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java index 9659434e03d..49815cdb703 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java @@ -29,7 +29,7 @@ import org.elasticsearch.cluster.NotMasterException; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.RoutingService; +import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; @@ -58,7 +58,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public class NodeJoinController extends AbstractComponent { private final ClusterService clusterService; - private final RoutingService routingService; + private final AllocationService allocationService; private final ElectMasterService electMaster; private final DiscoverySettings discoverySettings; private final JoinTaskExecutor joinTaskExecutor = new JoinTaskExecutor(); @@ -68,10 +68,11 @@ public class NodeJoinController extends AbstractComponent { private ElectionContext electionContext = null; - public NodeJoinController(ClusterService clusterService, RoutingService routingService, ElectMasterService electMaster, DiscoverySettings discoverySettings, Settings settings) { + public NodeJoinController(ClusterService clusterService, AllocationService allocationService, ElectMasterService electMaster, + DiscoverySettings discoverySettings, Settings settings) { super(settings); this.clusterService = clusterService; - this.routingService = routingService; + this.allocationService = allocationService; this.electMaster = electMaster; this.discoverySettings = discoverySettings; } @@ -406,21 +407,7 @@ public class NodeJoinController extends AbstractComponent { ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(currentState.blocks()) .removeGlobalBlock(discoverySettings.getNoMasterBlock()).build(); newState.blocks(clusterBlocks); - newState.nodes(nodesBuilder); nodesChanged = true; - - // reroute now to remove any dead nodes (master may have stepped down when they left and didn't update the routing table) - // Note: also do it now to avoid assigning shards to these nodes. We will have another reroute after the cluster - // state is published. - // TODO: this publishing of a cluster state with no nodes assigned to joining nodes shouldn't be needed anymore. remove. - - final ClusterState tmpState = newState.build(); - RoutingAllocation.Result result = routingService.getAllocationService().reroute(tmpState, "nodes joined"); - newState = ClusterState.builder(tmpState); - if (result.changed()) { - newState.routingResult(result); - } - nodesBuilder = DiscoveryNodes.builder(tmpState.nodes()); } if (nodesBuilder.isLocalNodeElectedMaster() == false) { @@ -439,7 +426,8 @@ public class NodeJoinController extends AbstractComponent { for (DiscoveryNode existingNode : currentNodes) { if (node.getAddress().equals(existingNode.getAddress())) { nodesBuilder.remove(existingNode.getId()); - logger.warn("received join request from node [{}], but found existing node {} with same address, removing existing node", node, existingNode); + logger.warn("received join request from node [{}], but found existing node {} with same address, " + + "removing existing node", node, existingNode); } } } @@ -448,6 +436,12 @@ public class NodeJoinController extends AbstractComponent { if (nodesChanged) { newState.nodes(nodesBuilder); + final ClusterState tmpState = newState.build(); + RoutingAllocation.Result result = allocationService.reroute(tmpState, "node_join"); + newState = ClusterState.builder(tmpState); + if (result.changed()) { + newState.routingResult(result); + } } // we must return a new cluster state instance to force publishing. This is important @@ -463,13 +457,6 @@ public class NodeJoinController extends AbstractComponent { @Override public void clusterStatePublished(ClusterChangedEvent event) { - if (event.nodesDelta().hasChanges()) { - // we reroute not in the same cluster state update since in certain areas we rely on - // the node to be in the cluster state (sampled from ClusterService#state) to be there, also - // shard transitions need to better be handled in such cases - routingService.reroute("post_node_add"); - } - NodeJoinController.this.electMaster.logMinimumMasterNodesWarningIfNecessary(event.previousState(), event.state()); } } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index 54ef9928585..6a9a64ff411 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -32,7 +32,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.RoutingService; +import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; @@ -113,7 +113,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen private final TransportService transportService; private final ClusterService clusterService; - private RoutingService routingService; + private AllocationService allocationService; private final ClusterName clusterName; private final DiscoverySettings discoverySettings; private final ZenPingService pingService; @@ -146,7 +146,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen /** counts the time this node has joined the cluster or have elected it self as master */ private final AtomicLong clusterJoinsCounter = new AtomicLong(); - // must initialized in doStart(), when we have the routingService set + // must initialized in doStart(), when we have the allocationService set private volatile NodeJoinController nodeJoinController; @Inject @@ -206,8 +206,8 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen } @Override - public void setRoutingService(RoutingService routingService) { - this.routingService = routingService; + public void setAllocationService(AllocationService allocationService) { + this.allocationService = allocationService; } @Override @@ -215,7 +215,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen nodesFD.setLocalNode(clusterService.localNode()); joinThreadControl.start(); pingService.start(); - this.nodeJoinController = new NodeJoinController(clusterService, routingService, electMaster, discoverySettings, settings); + this.nodeJoinController = new NodeJoinController(clusterService, allocationService, electMaster, discoverySettings, settings); } @Override @@ -516,8 +516,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen return rejoin(currentState, "not enough master nodes"); } // eagerly run reroute to remove dead nodes from routing table - RoutingAllocation.Result routingResult = routingService.getAllocationService().reroute( - ClusterState.builder(currentState).build(), + RoutingAllocation.Result routingResult = allocationService.reroute(ClusterState.builder(currentState).build(), "[" + node + "] left"); return ClusterState.builder(currentState).routingResult(routingResult).build(); } @@ -561,7 +560,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen return rejoin(currentState, "not enough master nodes"); } // eagerly run reroute to remove dead nodes from routing table - RoutingAllocation.Result routingResult = routingService.getAllocationService().reroute( + RoutingAllocation.Result routingResult = allocationService.reroute( ClusterState.builder(currentState).build(), "[" + node + "] failed"); return ClusterState.builder(currentState).routingResult(routingResult).build(); diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index f34e16db140..043526306e9 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -37,6 +37,7 @@ import org.elasticsearch.cluster.action.index.MappingUpdatedAction; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeService; import org.elasticsearch.cluster.routing.RoutingService; +import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.StopWatch; import org.elasticsearch.common.component.Lifecycle; @@ -321,7 +322,7 @@ public class Node implements Closeable { ESLogger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings)); logger.info("starting ..."); // hack around dependency injection problem (for now...) - injector.getInstance(Discovery.class).setRoutingService(injector.getInstance(RoutingService.class)); + injector.getInstance(Discovery.class).setAllocationService(injector.getInstance(AllocationService.class)); for (Class plugin : pluginsService.nodeServices()) { injector.getInstance(plugin).start(); } diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java index 27c38e66074..683bebc55a3 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.NotMasterException; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.RoutingService; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation; @@ -99,7 +98,7 @@ public class NodeJoinControllerTests extends ESTestCase { // make sure we have a master setState(clusterService, ClusterState.builder(clusterService.state()).nodes( DiscoveryNodes.builder(initialNodes).masterNodeId(localNode.getId()))); - nodeJoinController = new NodeJoinController(clusterService, new NoopRoutingService(Settings.EMPTY), + nodeJoinController = new NodeJoinController(clusterService, new NoopAllocationService(Settings.EMPTY), new ElectMasterService(Settings.EMPTY, Version.CURRENT), new DiscoverySettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), Settings.EMPTY); @@ -298,7 +297,8 @@ public class NodeJoinControllerTests extends ESTestCase { } logger.debug("--> asserting master election didn't finish yet"); - assertThat("election finished after [" + initialJoins + "] master nodes but required joins is [" + requiredJoins + "]", electionFuture.isDone(), equalTo(false)); + assertThat("election finished after [" + initialJoins + "] master nodes but required joins is [" + requiredJoins + "]", + electionFuture.isDone(), equalTo(false)); final int finalJoins = requiredJoins - initialJoins + randomInt(5); nodesToJoin.clear(); @@ -374,7 +374,8 @@ public class NodeJoinControllerTests extends ESTestCase { nodeJoinController.waitToBeElectedAsMaster(requiredJoins, TimeValue.timeValueMillis(1), new NodeJoinController.ElectionCallback() { @Override public void onElectedAsMaster(ClusterState state) { - assertThat("callback called with elected as master, but state disagrees", state.nodes().isLocalNodeElectedMaster(), equalTo(true)); + assertThat("callback called with elected as master, but state disagrees", state.nodes().isLocalNodeElectedMaster(), + equalTo(true)); latch.countDown(); } @@ -492,7 +493,8 @@ public class NodeJoinControllerTests extends ESTestCase { nodeJoinController.waitToBeElectedAsMaster(requiredJoins, TimeValue.timeValueHours(30), new NodeJoinController.ElectionCallback() { @Override public void onElectedAsMaster(ClusterState state) { - assertThat("callback called with elected as master, but state disagrees", state.nodes().isLocalNodeElectedMaster(), equalTo(true)); + assertThat("callback called with elected as master, but state disagrees", state.nodes().isLocalNodeElectedMaster(), + equalTo(true)); latch.countDown(); } @@ -516,18 +518,6 @@ public class NodeJoinControllerTests extends ESTestCase { } - static class NoopRoutingService extends RoutingService { - - public NoopRoutingService(Settings settings) { - super(settings, null, new NoopAllocationService(settings)); - } - - @Override - protected void performReroute(String reason) { - - } - } - static class NoopAllocationService extends AllocationService { public NoopAllocationService(Settings settings) { @@ -535,12 +525,14 @@ public class NodeJoinControllerTests extends ESTestCase { } @Override - public RoutingAllocation.Result applyStartedShards(ClusterState clusterState, List startedShards, boolean withReroute) { + public RoutingAllocation.Result applyStartedShards(ClusterState clusterState, List startedShards, + boolean withReroute) { return new RoutingAllocation.Result(false, clusterState.routingTable(), clusterState.metaData()); } @Override - public RoutingAllocation.Result applyFailedShards(ClusterState clusterState, List failedShards) { + public RoutingAllocation.Result applyFailedShards(ClusterState clusterState, + List failedShards) { return new RoutingAllocation.Result(false, clusterState.routingTable(), clusterState.metaData()); } diff --git a/core/src/test/java/org/elasticsearch/test/NoopDiscovery.java b/core/src/test/java/org/elasticsearch/test/NoopDiscovery.java index 3193aaf458e..967837e0044 100644 --- a/core/src/test/java/org/elasticsearch/test/NoopDiscovery.java +++ b/core/src/test/java/org/elasticsearch/test/NoopDiscovery.java @@ -20,7 +20,7 @@ package org.elasticsearch.test; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.RoutingService; +import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.common.component.Lifecycle; import org.elasticsearch.common.component.LifecycleListener; import org.elasticsearch.discovery.Discovery; @@ -41,7 +41,7 @@ public class NoopDiscovery implements Discovery { } @Override - public void setRoutingService(RoutingService routingService) { + public void setAllocationService(AllocationService allocationService) { } From a3bd2de430a2195ad64937d72f0cdd878420cea5 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Fri, 17 Jun 2016 12:14:45 -0400 Subject: [PATCH 35/87] [DOCS] fix missing rollover-index link --- docs/reference/indices.asciidoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/reference/indices.asciidoc b/docs/reference/indices.asciidoc index cad1a1477bd..3c1eadfa07e 100644 --- a/docs/reference/indices.asciidoc +++ b/docs/reference/indices.asciidoc @@ -76,6 +76,8 @@ include::indices/open-close.asciidoc[] include::indices/shrink-index.asciidoc[] +include::indices/rollover-index.asciidoc[] + include::indices/put-mapping.asciidoc[] include::indices/get-mapping.asciidoc[] From 245def80f04c7d33a4fe10f873903ca23c561947 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 17 Jun 2016 15:17:56 -0400 Subject: [PATCH 36/87] Add note that thread pool settings are node-level This commit adds a note to the breaking changes docs that since commit da74323141a69bd06fc19a70bc072143e9f0e986, thread pool settings are no longer cluster-level settings and thus not dynamically updatable. --- docs/reference/migration/migrate_5_0/settings.asciidoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/reference/migration/migrate_5_0/settings.asciidoc b/docs/reference/migration/migrate_5_0/settings.asciidoc index ed405428ab6..4863588818f 100644 --- a/docs/reference/migration/migrate_5_0/settings.asciidoc +++ b/docs/reference/migration/migrate_5_0/settings.asciidoc @@ -92,6 +92,9 @@ The queue size setting for a fixed thread pool must be `queue_size` (all other variants that were previously supported are no longer supported). +Thread pool settings are now node-level settings. As such, it is not +possible to update thread pool settings via the cluster settings API. + ==== Analysis settings The `index.analysis.analyzer.default_index` analyzer is not supported anymore. From d09d89f8c57c35146387268fc536d86b77d82435 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 17 Jun 2016 15:27:46 -0400 Subject: [PATCH 37/87] Remove only node preference This commit removes the search preference _only_node as the same functionality can be obtained by using the search preference _only_nodes. This commit also adds a test that ensures that _only_nodes will continue to support specifying node IDs. Relates #18875 --- .../routing/IndexShardRoutingTable.java | 10 ++- .../cluster/routing/OperationRouting.java | 4 -- .../cluster/routing/Preference.java | 7 -- .../routing/OperationRoutingTests.java | 64 ++++++++++++++++++- .../recovery/RecoveryWhileUnderLoadIT.java | 2 +- .../search/preference/SearchPreferenceIT.java | 6 +- .../migration/migrate_5_0/search.asciidoc | 6 +- .../search/request/preference.asciidoc | 4 -- 8 files changed, 80 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java index ceea83dbcaa..91b1df9b453 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java @@ -37,6 +37,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -369,8 +370,13 @@ public class IndexShardRoutingTable implements Iterable { } } if (ordered.isEmpty()) { - throw new IllegalArgumentException("no data nodes with critera(s) " + - Strings.arrayToCommaDelimitedString(nodeAttributes) + "] found for shard:" + shardId()); + final String message = String.format( + Locale.ROOT, + "no data nodes with %s [%s] found for shard: %s", + nodeAttributes.length == 1 ? "criteria" : "criterion", + String.join(",", nodeAttributes), + shardId()); + throw new IllegalArgumentException(message); } return new PlainShardIterator(shardId, ordered); } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 19189e0c286..5b24ac7edff 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -177,10 +177,6 @@ public class OperationRouting extends AbstractComponent { return indexShard.replicaFirstActiveInitializingShardsIt(); case ONLY_LOCAL: return indexShard.onlyNodeActiveInitializingShardsIt(localNodeId); - case ONLY_NODE: - String nodeId = preference.substring(Preference.ONLY_NODE.type().length() + 1); - ensureNodeIdExists(nodes, nodeId); - return indexShard.onlyNodeActiveInitializingShardsIt(nodeId); case ONLY_NODES: String nodeAttributes = preference.substring(Preference.ONLY_NODES.type().length() + 1); return indexShard.onlyNodeSelectorActiveInitializingShardsIt(nodeAttributes.split(","), nodes); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/Preference.java b/core/src/main/java/org/elasticsearch/cluster/routing/Preference.java index cf0dd6cc54d..d4685d7aead 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/Preference.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/Preference.java @@ -64,11 +64,6 @@ public enum Preference { */ ONLY_LOCAL("_only_local"), - /** - * Route to specific node only - */ - ONLY_NODE("_only_node"), - /** * Route to only node with attribute */ @@ -100,8 +95,6 @@ public enum Preference { return SHARDS; case "_prefer_nodes": return PREFER_NODES; - case "_only_node": - return ONLY_NODE; case "_local": return LOCAL; case "_primary": diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java index 370ac52956c..3118692b341 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java @@ -41,7 +41,9 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.object.HasToString.hasToString; import static org.hamcrest.Matchers.equalTo; public class OperationRoutingTests extends ESTestCase{ @@ -211,8 +213,7 @@ public class OperationRoutingTests extends ESTestCase{ } } final ShardIterator it = - new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, - ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) + new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) .getShards(clusterService.state(), indexName, 0, "_prefer_nodes:" + String.join(",", nodes)); final List all = new ArrayList<>(); ShardRouting shard; @@ -231,4 +232,63 @@ public class OperationRoutingTests extends ESTestCase{ } } + public void testThatOnlyNodesSupportNodeIds() throws InterruptedException, IOException { + TestThreadPool threadPool = null; + ClusterService clusterService = null; + try { + threadPool = new TestThreadPool("testThatOnlyNodesSupportNodeIds"); + clusterService = ClusterServiceUtils.createClusterService(threadPool); + final String indexName = "test"; + ClusterServiceUtils.setState(clusterService, ClusterStateCreationUtils.stateWithActivePrimary(indexName, true, randomInt(8))); + final Index index = clusterService.state().metaData().index(indexName).getIndex(); + final List shards = clusterService.state().getRoutingNodes().assignedShards(new ShardId(index, 0)); + final int count = randomIntBetween(1, shards.size()); + int position = 0; + final List nodes = new ArrayList<>(); + final List expected = new ArrayList<>(); + for (int i = 0; i < count; i++) { + if (randomBoolean() && !shards.get(position).initializing()) { + nodes.add(shards.get(position).currentNodeId()); + expected.add(shards.get(position)); + position++; + } else { + nodes.add("missing_" + i); + } + } + if (expected.size() > 0) { + final ShardIterator it = + new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) + .getShards(clusterService.state(), indexName, 0, "_only_nodes:" + String.join(",", nodes)); + final List only = new ArrayList<>(); + ShardRouting shard; + while ((shard = it.nextOrNull()) != null) { + only.add(shard); + } + assertThat(new HashSet<>(only), equalTo(new HashSet<>(expected))); + } else { + final ClusterService cs = clusterService; + final IllegalArgumentException e = expectThrows( + IllegalArgumentException.class, + () -> new OperationRouting( + Settings.EMPTY, + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) + .getShards(cs.state(), indexName, 0, "_only_nodes:" + String.join(",", nodes))); + if (nodes.size() == 1) { + assertThat( + e, + hasToString(containsString( + "no data nodes with criteria [" + String.join(",", nodes) + "] found for shard: [test][0]"))); + } else { + assertThat( + e, + hasToString(containsString( + "no data nodes with criterion [" + String.join(",", nodes) + "] found for shard: [test][0]"))); + } + } + } finally { + IOUtils.close(clusterService); + terminate(threadPool); + } + } + } diff --git a/core/src/test/java/org/elasticsearch/recovery/RecoveryWhileUnderLoadIT.java b/core/src/test/java/org/elasticsearch/recovery/RecoveryWhileUnderLoadIT.java index 5f6636a1bd7..63b572f4d56 100644 --- a/core/src/test/java/org/elasticsearch/recovery/RecoveryWhileUnderLoadIT.java +++ b/core/src/test/java/org/elasticsearch/recovery/RecoveryWhileUnderLoadIT.java @@ -296,7 +296,7 @@ public class RecoveryWhileUnderLoadIT extends ESIntegTestCase { if (docShard.id() == shard) { for (ShardRouting shardRouting : state.routingTable().shardRoutingTable("test", shard)) { GetResponse response = client().prepareGet("test", "type", Long.toString(id)) - .setPreference("_only_node:" + shardRouting.currentNodeId()).get(); + .setPreference("_only_nodes:" + shardRouting.currentNodeId()).get(); if (response.isExists()) { logger.info("missing id [{}] on shard {}", id, shardRouting); } diff --git a/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java b/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java index 49142988a46..49046bae009 100644 --- a/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java +++ b/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java @@ -38,7 +38,9 @@ import java.util.Set; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.greaterThan; @@ -157,10 +159,10 @@ public class SearchPreferenceIT extends ESIntegTestCase { ensureGreen(); try { - client().prepareSearch().setQuery(matchAllQuery()).setPreference("_only_node:DOES-NOT-EXIST").execute().actionGet(); + client().prepareSearch().setQuery(matchAllQuery()).setPreference("_only_nodes:DOES-NOT-EXIST").execute().actionGet(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), is("No data node with id[DOES-NOT-EXIST] found")); + assertThat(e, hasToString(containsString("no data nodes with criteria [DOES-NOT-EXIST] found for shard: [test]["))); } } diff --git a/docs/reference/migration/migrate_5_0/search.asciidoc b/docs/reference/migration/migrate_5_0/search.asciidoc index c20df657504..7ebd79e66ca 100644 --- a/docs/reference/migration/migrate_5_0/search.asciidoc +++ b/docs/reference/migration/migrate_5_0/search.asciidoc @@ -186,7 +186,11 @@ In the response for profiling queries, the `query_type` has been renamed to `typ `description`. These changes have been made so the response format is more friendly to supporting other types of profiling in the future. -==== Search prefernce +==== Search preferences + +The <> `_only_node` has +been removed. The same behavior can be achieved by using `_only_nodes` +and specifying a single node ID. The <> `_prefer_node` has been superseded by `_prefer_nodes`. By specifying a single node, diff --git a/docs/reference/search/request/preference.asciidoc b/docs/reference/search/request/preference.asciidoc index 761fdeaa369..d5237812b98 100644 --- a/docs/reference/search/request/preference.asciidoc +++ b/docs/reference/search/request/preference.asciidoc @@ -27,10 +27,6 @@ The `preference` is a query string parameter which can be set to: The operation will prefer to be executed on a local allocated shard if possible. -`_only_node:xyz`:: - Restricts the search to execute only on a node with - the provided node id (`xyz` in this case). - `_prefer_nodes:abc,xyz`:: Prefers execution on the nodes with the provided node ids (`abc` or `xyz` in this case) if applicable. From 1e16c22d0340146834634ede17e3b69bf982c947 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 16 Jun 2016 17:29:10 -0400 Subject: [PATCH 38/87] Painless: move semicolon hack into lexer Perviously we used token level lookbehind in the parser. That worked, but only if the parser didn't have any ambiguity *at all*. Since the parser has ambiguity it didn't work everywhere. In particular it failed when parsing blocks in lambdas like `a -> {int b = a + 2; b * b}`. This moves the hack from the parser into the lexer. There we can use token lookbehind (same trick) to *insert* semicolons into the token stream. This works much better for antlr because antlr's prediction code can work with real tokens. Also, the lexer is simpler than the parser, so if there is a place to introduce a hack, that is a better place. --- .../src/main/antlr/PainlessLexer.g4 | 4 +- .../src/main/antlr/PainlessParser.g4 | 11 - .../painless/antlr/EnhancedPainlessLexer.java | 96 +++ .../painless/antlr/PainlessLexer.java | 4 +- .../painless/antlr/PainlessParser.java | 740 +++++++++--------- .../painless/antlr/SlashStrategy.java | 7 +- .../elasticsearch/painless/antlr/Walker.java | 2 +- .../elasticsearch/painless/LambdaTests.java | 6 +- .../elasticsearch/painless/RegexTests.java | 2 +- .../painless/antlr/ParserTests.java | 2 +- 10 files changed, 471 insertions(+), 403 deletions(-) create mode 100644 modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java diff --git a/modules/lang-painless/src/main/antlr/PainlessLexer.g4 b/modules/lang-painless/src/main/antlr/PainlessLexer.g4 index 62a154db40c..ca469eed69a 100644 --- a/modules/lang-painless/src/main/antlr/PainlessLexer.g4 +++ b/modules/lang-painless/src/main/antlr/PainlessLexer.g4 @@ -56,7 +56,7 @@ THIS: 'this'; BOOLNOT: '!'; BWNOT: '~'; MUL: '*'; -DIV: '/' { false == SlashStrategy.slashIsRegex(_factory) }?; +DIV: '/' { false == SlashStrategy.slashIsRegex(this) }?; REM: '%'; ADD: '+'; SUB: '-'; @@ -104,7 +104,7 @@ INTEGER: ( '0' | [1-9] [0-9]* ) [lLfFdD]?; DECIMAL: ( '0' | [1-9] [0-9]* ) (DOT [0-9]+)? ( [eE] [+\-]? [0-9]+ )? [fF]?; STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' ) | ( '\'' ( '\\\'' | '\\\\' | ~[\\"] )*? '\'' ); -REGEX: '/' ( ~('/' | '\n') | '\\' ~'\n' )+ '/' [cilmsUux]* { SlashStrategy.slashIsRegex(_factory) }?; +REGEX: '/' ( ~('/' | '\n') | '\\' ~'\n' )+ '/' [cilmsUux]* { SlashStrategy.slashIsRegex(this) }?; TRUE: 'true'; FALSE: 'false'; diff --git a/modules/lang-painless/src/main/antlr/PainlessParser.g4 b/modules/lang-painless/src/main/antlr/PainlessParser.g4 index 6dbaa50c73d..037d8fd7bbd 100644 --- a/modules/lang-painless/src/main/antlr/PainlessParser.g4 +++ b/modules/lang-painless/src/main/antlr/PainlessParser.g4 @@ -92,17 +92,6 @@ trap delimiter : SEMICOLON | EOF - // RBRACK is a delimiter but we don't consume it because it is only valid - // in places where RBRACK can follow the statement. It is simpler to not - // consume it here then it is to consume it here. Unfortunately, they - // obvious syntax to do this `| { _input.LA(1) == RBRACK }?` generates an - // amazingly intense `adaptivePredict` call that doesn't actually work - // and builds a serious DFA. Huge. So instead we use standard ANTLR syntax - // to consume the token and then undo the consumption. This looks hairy but - // it is better than the alternatives. - | { int mark = _input.mark(); int index = _input.index(); } - RBRACK - { _input.seek(index); _input.release(mark); } ; // Note we return the boolean s. This is returned as true diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java new file mode 100644 index 00000000000..94a2c258974 --- /dev/null +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java @@ -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.painless.antlr; + +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.LexerNoViableAltException; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenSource; +import org.antlr.v4.runtime.misc.Interval; +import org.antlr.v4.runtime.misc.Pair; +import org.elasticsearch.painless.Location; + +/** + * A lexer that is customized for painless. It will: + *
    + *
  • will override the default error behavior to fail on the first error + *
  • store the last token in case we need to do lookbehind for semicolon insertion and regex vs division detection + *
  • insert semicolons where they'd improve the language's readability. Rather than hack this into the parser and create a ton of + * ambiguity we hack them here where we can use heuristics to do it quickly. + *
+ */ +final class EnhancedPainlessLexer extends PainlessLexer { + final String sourceName; + private Token stashedNext = null; + private Token previous = null; + + EnhancedPainlessLexer(CharStream charStream, String sourceName) { + super(charStream); + this.sourceName = sourceName; + } + + public Token getPreviousToken() { + return previous; + } + + @Override + public Token nextToken() { + if (stashedNext != null) { + previous = stashedNext; + stashedNext = null; + return previous; + } + Token next = super.nextToken(); + if (insertSemicolon(previous, next)) { + stashedNext = next; + previous = _factory.create(new Pair(this, _input), PainlessLexer.SEMICOLON, ";", + Lexer.DEFAULT_TOKEN_CHANNEL, next.getStartIndex(), next.getStopIndex(), next.getLine(), next.getCharPositionInLine()); + return previous; + } else { + previous = next; + return next; + } + } + + @Override + public void recover(final LexerNoViableAltException lnvae) { + final CharStream charStream = lnvae.getInputStream(); + final int startIndex = lnvae.getStartIndex(); + final String text = charStream.getText(Interval.of(startIndex, charStream.index())); + + Location location = new Location(sourceName, _tokenStartCharIndex); + throw location.createError(new IllegalArgumentException("unexpected character [" + getErrorDisplay(text) + "].", lnvae)); + } + + private static boolean insertSemicolon(Token previous, Token next) { + if (previous == null || next.getType() != PainlessLexer.RBRACK) { + return false; + } + switch (previous.getType()) { + case PainlessLexer.RBRACK: // };} would be weird! + case PainlessLexer.SEMICOLON: // already have a semicolon, no need to add one + case PainlessLexer.LBRACK: // empty blocks don't need a semicolon + return false; + default: + return true; + } + } +} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java index cf0ac8605f0..f512ad20d7e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessLexer.java @@ -140,14 +140,14 @@ class PainlessLexer extends Lexer { private boolean DIV_sempred(RuleContext _localctx, int predIndex) { switch (predIndex) { case 0: - return false == SlashStrategy.slashIsRegex(_factory) ; + return false == SlashStrategy.slashIsRegex(this) ; } return true; } private boolean REGEX_sempred(RuleContext _localctx, int predIndex) { switch (predIndex) { case 1: - return SlashStrategy.slashIsRegex(_factory) ; + return SlashStrategy.slashIsRegex(this) ; } return true; } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java index 7b994e699a2..39d1ca3d188 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/PainlessParser.java @@ -1287,7 +1287,6 @@ class PainlessParser extends Parser { public static class DelimiterContext extends ParserRuleContext { public TerminalNode SEMICOLON() { return getToken(PainlessParser.SEMICOLON, 0); } public TerminalNode EOF() { return getToken(PainlessParser.EOF, 0); } - public TerminalNode RBRACK() { return getToken(PainlessParser.RBRACK, 0); } public DelimiterContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); } @@ -1302,34 +1301,17 @@ class PainlessParser extends Parser { public final DelimiterContext delimiter() throws RecognitionException { DelimiterContext _localctx = new DelimiterContext(_ctx, getState()); enterRule(_localctx, 26, RULE_delimiter); + int _la; try { - setState(230); - switch (_input.LA(1)) { - case SEMICOLON: - enterOuterAlt(_localctx, 1); - { - setState(225); - match(SEMICOLON); - } - break; - case EOF: - enterOuterAlt(_localctx, 2); - { - setState(226); - match(EOF); - } - break; - case RBRACK: - enterOuterAlt(_localctx, 3); - { - int mark = _input.mark(); int index = _input.index(); - setState(228); - match(RBRACK); - _input.seek(index); _input.release(mark); - } - break; - default: - throw new NoViableAltException(this); + enterOuterAlt(_localctx, 1); + { + setState(225); + _la = _input.LA(1); + if ( !(_la==EOF || _la==SEMICOLON) ) { + _errHandler.recoverInline(this); + } else { + consume(); + } } } catch (RecognitionException re) { @@ -1494,24 +1476,24 @@ class PainlessParser extends Parser { int _alt; enterOuterAlt(_localctx, 1); { - setState(241); - switch ( getInterpreter().adaptivePredict(_input,19,_ctx) ) { + setState(236); + switch ( getInterpreter().adaptivePredict(_input,18,_ctx) ) { case 1: { _localctx = new AssignmentContext(_localctx); _ctx = _localctx; _prevctx = _localctx; - setState(233); + setState(228); chain(true); - setState(234); + setState(229); _la = _input.LA(1); if ( !(((((_la - 56)) & ~0x3f) == 0 && ((1L << (_la - 56)) & ((1L << (ASSIGN - 56)) | (1L << (AADD - 56)) | (1L << (ASUB - 56)) | (1L << (AMUL - 56)) | (1L << (ADIV - 56)) | (1L << (AREM - 56)) | (1L << (AAND - 56)) | (1L << (AXOR - 56)) | (1L << (AOR - 56)) | (1L << (ALSH - 56)) | (1L << (ARSH - 56)) | (1L << (AUSH - 56)))) != 0)) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(235); + setState(230); expression(1); ((AssignmentContext)_localctx).s = false; } @@ -1521,37 +1503,37 @@ class PainlessParser extends Parser { _localctx = new SingleContext(_localctx); _ctx = _localctx; _prevctx = _localctx; - setState(238); + setState(233); ((SingleContext)_localctx).u = unary(false); ((SingleContext)_localctx).s = ((SingleContext)_localctx).u.s; } break; } _ctx.stop = _input.LT(-1); - setState(307); + setState(302); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,21,_ctx); + _alt = getInterpreter().adaptivePredict(_input,20,_ctx); while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { if ( _alt==1 ) { if ( _parseListeners!=null ) triggerExitRuleEvent(); _prevctx = _localctx; { - setState(305); - switch ( getInterpreter().adaptivePredict(_input,20,_ctx) ) { + setState(300); + switch ( getInterpreter().adaptivePredict(_input,19,_ctx) ) { case 1: { _localctx = new BinaryContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(243); + setState(238); if (!(precpred(_ctx, 13))) throw new FailedPredicateException(this, "precpred(_ctx, 13)"); - setState(244); + setState(239); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << MUL) | (1L << DIV) | (1L << REM))) != 0)) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(245); + setState(240); expression(14); ((BinaryContext)_localctx).s = false; } @@ -1560,16 +1542,16 @@ class PainlessParser extends Parser { { _localctx = new BinaryContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(248); + setState(243); if (!(precpred(_ctx, 12))) throw new FailedPredicateException(this, "precpred(_ctx, 12)"); - setState(249); + setState(244); _la = _input.LA(1); if ( !(_la==ADD || _la==SUB) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(250); + setState(245); expression(13); ((BinaryContext)_localctx).s = false; } @@ -1578,16 +1560,16 @@ class PainlessParser extends Parser { { _localctx = new BinaryContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(253); + setState(248); if (!(precpred(_ctx, 11))) throw new FailedPredicateException(this, "precpred(_ctx, 11)"); - setState(254); + setState(249); _la = _input.LA(1); if ( !(_la==FIND || _la==MATCH) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(255); + setState(250); expression(12); ((BinaryContext)_localctx).s = false; } @@ -1596,16 +1578,16 @@ class PainlessParser extends Parser { { _localctx = new BinaryContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(258); + setState(253); if (!(precpred(_ctx, 10))) throw new FailedPredicateException(this, "precpred(_ctx, 10)"); - setState(259); + setState(254); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << LSH) | (1L << RSH) | (1L << USH))) != 0)) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(260); + setState(255); expression(11); ((BinaryContext)_localctx).s = false; } @@ -1614,16 +1596,16 @@ class PainlessParser extends Parser { { _localctx = new CompContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(263); + setState(258); if (!(precpred(_ctx, 9))) throw new FailedPredicateException(this, "precpred(_ctx, 9)"); - setState(264); + setState(259); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << LT) | (1L << LTE) | (1L << GT) | (1L << GTE))) != 0)) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(265); + setState(260); expression(10); ((CompContext)_localctx).s = false; } @@ -1632,16 +1614,16 @@ class PainlessParser extends Parser { { _localctx = new CompContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(268); + setState(263); if (!(precpred(_ctx, 8))) throw new FailedPredicateException(this, "precpred(_ctx, 8)"); - setState(269); + setState(264); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << EQ) | (1L << EQR) | (1L << NE) | (1L << NER))) != 0)) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(270); + setState(265); expression(9); ((CompContext)_localctx).s = false; } @@ -1650,11 +1632,11 @@ class PainlessParser extends Parser { { _localctx = new BinaryContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(273); + setState(268); if (!(precpred(_ctx, 7))) throw new FailedPredicateException(this, "precpred(_ctx, 7)"); - setState(274); + setState(269); match(BWAND); - setState(275); + setState(270); expression(8); ((BinaryContext)_localctx).s = false; } @@ -1663,11 +1645,11 @@ class PainlessParser extends Parser { { _localctx = new BinaryContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(278); + setState(273); if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)"); - setState(279); + setState(274); match(XOR); - setState(280); + setState(275); expression(7); ((BinaryContext)_localctx).s = false; } @@ -1676,11 +1658,11 @@ class PainlessParser extends Parser { { _localctx = new BinaryContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(283); + setState(278); if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)"); - setState(284); + setState(279); match(BWOR); - setState(285); + setState(280); expression(6); ((BinaryContext)_localctx).s = false; } @@ -1689,11 +1671,11 @@ class PainlessParser extends Parser { { _localctx = new BoolContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(288); + setState(283); if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)"); - setState(289); + setState(284); match(BOOLAND); - setState(290); + setState(285); expression(5); ((BoolContext)_localctx).s = false; } @@ -1702,11 +1684,11 @@ class PainlessParser extends Parser { { _localctx = new BoolContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(293); + setState(288); if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)"); - setState(294); + setState(289); match(BOOLOR); - setState(295); + setState(290); expression(4); ((BoolContext)_localctx).s = false; } @@ -1715,15 +1697,15 @@ class PainlessParser extends Parser { { _localctx = new ConditionalContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(298); + setState(293); if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)"); - setState(299); + setState(294); match(COND); - setState(300); + setState(295); ((ConditionalContext)_localctx).e0 = expression(0); - setState(301); + setState(296); match(COLON); - setState(302); + setState(297); ((ConditionalContext)_localctx).e1 = expression(2); ((ConditionalContext)_localctx).s = ((ConditionalContext)_localctx).e0.s && ((ConditionalContext)_localctx).e1.s; } @@ -1731,9 +1713,9 @@ class PainlessParser extends Parser { } } } - setState(309); + setState(304); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,21,_ctx); + _alt = getInterpreter().adaptivePredict(_input,20,_ctx); } } } @@ -1878,22 +1860,22 @@ class PainlessParser extends Parser { enterRule(_localctx, 30, RULE_unary); int _la; try { - setState(339); - switch ( getInterpreter().adaptivePredict(_input,22,_ctx) ) { + setState(334); + switch ( getInterpreter().adaptivePredict(_input,21,_ctx) ) { case 1: _localctx = new PreContext(_localctx); enterOuterAlt(_localctx, 1); { - setState(310); + setState(305); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(311); + setState(306); _la = _input.LA(1); if ( !(_la==INCR || _la==DECR) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(312); + setState(307); chain(true); } break; @@ -1901,11 +1883,11 @@ class PainlessParser extends Parser { _localctx = new PostContext(_localctx); enterOuterAlt(_localctx, 2); { - setState(313); + setState(308); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(314); + setState(309); chain(true); - setState(315); + setState(310); _la = _input.LA(1); if ( !(_la==INCR || _la==DECR) ) { _errHandler.recoverInline(this); @@ -1918,9 +1900,9 @@ class PainlessParser extends Parser { _localctx = new ReadContext(_localctx); enterOuterAlt(_localctx, 3); { - setState(317); + setState(312); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(318); + setState(313); chain(false); } break; @@ -1928,9 +1910,9 @@ class PainlessParser extends Parser { _localctx = new NumericContext(_localctx); enterOuterAlt(_localctx, 4); { - setState(319); + setState(314); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(320); + setState(315); _la = _input.LA(1); if ( !(((((_la - 68)) & ~0x3f) == 0 && ((1L << (_la - 68)) & ((1L << (OCTAL - 68)) | (1L << (HEX - 68)) | (1L << (INTEGER - 68)) | (1L << (DECIMAL - 68)))) != 0)) ) { _errHandler.recoverInline(this); @@ -1944,9 +1926,9 @@ class PainlessParser extends Parser { _localctx = new TrueContext(_localctx); enterOuterAlt(_localctx, 5); { - setState(322); + setState(317); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(323); + setState(318); match(TRUE); ((TrueContext)_localctx).s = false; } @@ -1955,9 +1937,9 @@ class PainlessParser extends Parser { _localctx = new FalseContext(_localctx); enterOuterAlt(_localctx, 6); { - setState(325); + setState(320); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(326); + setState(321); match(FALSE); ((FalseContext)_localctx).s = false; } @@ -1966,9 +1948,9 @@ class PainlessParser extends Parser { _localctx = new NullContext(_localctx); enterOuterAlt(_localctx, 7); { - setState(328); + setState(323); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(329); + setState(324); match(NULL); ((NullContext)_localctx).s = false; } @@ -1977,16 +1959,16 @@ class PainlessParser extends Parser { _localctx = new OperatorContext(_localctx); enterOuterAlt(_localctx, 8); { - setState(331); + setState(326); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(332); + setState(327); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << BOOLNOT) | (1L << BWNOT) | (1L << ADD) | (1L << SUB))) != 0)) ) { _errHandler.recoverInline(this); } else { consume(); } - setState(333); + setState(328); unary(false); } break; @@ -1994,13 +1976,13 @@ class PainlessParser extends Parser { _localctx = new CastContext(_localctx); enterOuterAlt(_localctx, 9); { - setState(334); + setState(329); match(LP); - setState(335); + setState(330); decltype(); - setState(336); + setState(331); match(RP); - setState(337); + setState(332); unary(_localctx.c); } break; @@ -2109,29 +2091,29 @@ class PainlessParser extends Parser { enterRule(_localctx, 32, RULE_chain); try { int _alt; - setState(375); - switch ( getInterpreter().adaptivePredict(_input,28,_ctx) ) { + setState(370); + switch ( getInterpreter().adaptivePredict(_input,27,_ctx) ) { case 1: _localctx = new DynamicContext(_localctx); enterOuterAlt(_localctx, 1); { - setState(341); + setState(336); ((DynamicContext)_localctx).p = primary(_localctx.c); - setState(345); + setState(340); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,23,_ctx); + _alt = getInterpreter().adaptivePredict(_input,22,_ctx); while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { if ( _alt==1 ) { { { - setState(342); + setState(337); secondary(((DynamicContext)_localctx).p.s); } } } - setState(347); + setState(342); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,23,_ctx); + _alt = getInterpreter().adaptivePredict(_input,22,_ctx); } } break; @@ -2139,25 +2121,25 @@ class PainlessParser extends Parser { _localctx = new StaticContext(_localctx); enterOuterAlt(_localctx, 2); { - setState(348); + setState(343); decltype(); - setState(349); + setState(344); dot(); - setState(353); + setState(348); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,24,_ctx); + _alt = getInterpreter().adaptivePredict(_input,23,_ctx); while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { if ( _alt==1 ) { { { - setState(350); + setState(345); secondary(true); } } } - setState(355); + setState(350); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,24,_ctx); + _alt = getInterpreter().adaptivePredict(_input,23,_ctx); } } break; @@ -2165,11 +2147,11 @@ class PainlessParser extends Parser { _localctx = new NewarrayContext(_localctx); enterOuterAlt(_localctx, 3); { - setState(356); + setState(351); match(NEW); - setState(357); + setState(352); match(TYPE); - setState(362); + setState(357); _errHandler.sync(this); _alt = 1; do { @@ -2177,11 +2159,11 @@ class PainlessParser extends Parser { case 1: { { - setState(358); + setState(353); match(LBRACE); - setState(359); + setState(354); expression(0); - setState(360); + setState(355); match(RBRACE); } } @@ -2189,31 +2171,31 @@ class PainlessParser extends Parser { default: throw new NoViableAltException(this); } - setState(364); + setState(359); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,25,_ctx); + _alt = getInterpreter().adaptivePredict(_input,24,_ctx); } while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ); - setState(373); - switch ( getInterpreter().adaptivePredict(_input,27,_ctx) ) { + setState(368); + switch ( getInterpreter().adaptivePredict(_input,26,_ctx) ) { case 1: { - setState(366); + setState(361); dot(); - setState(370); + setState(365); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,26,_ctx); + _alt = getInterpreter().adaptivePredict(_input,25,_ctx); while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { if ( _alt==1 ) { { { - setState(367); + setState(362); secondary(true); } } } - setState(372); + setState(367); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,26,_ctx); + _alt = getInterpreter().adaptivePredict(_input,25,_ctx); } } break; @@ -2334,19 +2316,19 @@ class PainlessParser extends Parser { PrimaryContext _localctx = new PrimaryContext(_ctx, getState(), c); enterRule(_localctx, 34, RULE_primary); try { - setState(396); - switch ( getInterpreter().adaptivePredict(_input,29,_ctx) ) { + setState(391); + switch ( getInterpreter().adaptivePredict(_input,28,_ctx) ) { case 1: _localctx = new ExprprecContext(_localctx); enterOuterAlt(_localctx, 1); { - setState(377); + setState(372); if (!( !_localctx.c )) throw new FailedPredicateException(this, " !$c "); - setState(378); + setState(373); match(LP); - setState(379); + setState(374); ((ExprprecContext)_localctx).e = expression(0); - setState(380); + setState(375); match(RP); ((ExprprecContext)_localctx).s = ((ExprprecContext)_localctx).e.s; } @@ -2355,13 +2337,13 @@ class PainlessParser extends Parser { _localctx = new ChainprecContext(_localctx); enterOuterAlt(_localctx, 2); { - setState(383); + setState(378); if (!( _localctx.c )) throw new FailedPredicateException(this, " $c "); - setState(384); + setState(379); match(LP); - setState(385); + setState(380); unary(true); - setState(386); + setState(381); match(RP); } break; @@ -2369,7 +2351,7 @@ class PainlessParser extends Parser { _localctx = new StringContext(_localctx); enterOuterAlt(_localctx, 3); { - setState(388); + setState(383); match(STRING); } break; @@ -2377,7 +2359,7 @@ class PainlessParser extends Parser { _localctx = new RegexContext(_localctx); enterOuterAlt(_localctx, 4); { - setState(389); + setState(384); match(REGEX); } break; @@ -2385,7 +2367,7 @@ class PainlessParser extends Parser { _localctx = new VariableContext(_localctx); enterOuterAlt(_localctx, 5); { - setState(390); + setState(385); match(ID); } break; @@ -2393,9 +2375,9 @@ class PainlessParser extends Parser { _localctx = new CalllocalContext(_localctx); enterOuterAlt(_localctx, 6); { - setState(391); + setState(386); match(ID); - setState(392); + setState(387); arguments(); } break; @@ -2403,11 +2385,11 @@ class PainlessParser extends Parser { _localctx = new NewobjectContext(_localctx); enterOuterAlt(_localctx, 7); { - setState(393); + setState(388); match(NEW); - setState(394); + setState(389); match(TYPE); - setState(395); + setState(390); arguments(); } break; @@ -2449,23 +2431,23 @@ class PainlessParser extends Parser { SecondaryContext _localctx = new SecondaryContext(_ctx, getState(), s); enterRule(_localctx, 36, RULE_secondary); try { - setState(402); - switch ( getInterpreter().adaptivePredict(_input,30,_ctx) ) { + setState(397); + switch ( getInterpreter().adaptivePredict(_input,29,_ctx) ) { case 1: enterOuterAlt(_localctx, 1); { - setState(398); + setState(393); if (!( _localctx.s )) throw new FailedPredicateException(this, " $s "); - setState(399); + setState(394); dot(); } break; case 2: enterOuterAlt(_localctx, 2); { - setState(400); + setState(395); if (!( _localctx.s )) throw new FailedPredicateException(this, " $s "); - setState(401); + setState(396); brace(); } break; @@ -2523,17 +2505,17 @@ class PainlessParser extends Parser { enterRule(_localctx, 38, RULE_dot); int _la; try { - setState(409); - switch ( getInterpreter().adaptivePredict(_input,31,_ctx) ) { + setState(404); + switch ( getInterpreter().adaptivePredict(_input,30,_ctx) ) { case 1: _localctx = new CallinvokeContext(_localctx); enterOuterAlt(_localctx, 1); { - setState(404); + setState(399); match(DOT); - setState(405); + setState(400); match(DOTID); - setState(406); + setState(401); arguments(); } break; @@ -2541,9 +2523,9 @@ class PainlessParser extends Parser { _localctx = new FieldaccessContext(_localctx); enterOuterAlt(_localctx, 2); { - setState(407); + setState(402); match(DOT); - setState(408); + setState(403); _la = _input.LA(1); if ( !(_la==DOTINTEGER || _la==DOTID) ) { _errHandler.recoverInline(this); @@ -2597,11 +2579,11 @@ class PainlessParser extends Parser { _localctx = new BraceaccessContext(_localctx); enterOuterAlt(_localctx, 1); { - setState(411); + setState(406); match(LBRACE); - setState(412); + setState(407); expression(0); - setState(413); + setState(408); match(RBRACE); } } @@ -2648,34 +2630,34 @@ class PainlessParser extends Parser { enterOuterAlt(_localctx, 1); { { - setState(415); + setState(410); match(LP); - setState(424); - switch ( getInterpreter().adaptivePredict(_input,33,_ctx) ) { + setState(419); + switch ( getInterpreter().adaptivePredict(_input,32,_ctx) ) { case 1: { - setState(416); + setState(411); argument(); - setState(421); + setState(416); _errHandler.sync(this); _la = _input.LA(1); while (_la==COMMA) { { { - setState(417); + setState(412); match(COMMA); - setState(418); + setState(413); argument(); } } - setState(423); + setState(418); _errHandler.sync(this); _la = _input.LA(1); } } break; } - setState(426); + setState(421); match(RP); } } @@ -2716,26 +2698,26 @@ class PainlessParser extends Parser { ArgumentContext _localctx = new ArgumentContext(_ctx, getState()); enterRule(_localctx, 44, RULE_argument); try { - setState(431); - switch ( getInterpreter().adaptivePredict(_input,34,_ctx) ) { + setState(426); + switch ( getInterpreter().adaptivePredict(_input,33,_ctx) ) { case 1: enterOuterAlt(_localctx, 1); { - setState(428); + setState(423); expression(0); } break; case 2: enterOuterAlt(_localctx, 2); { - setState(429); + setState(424); lambda(); } break; case 3: enterOuterAlt(_localctx, 3); { - setState(430); + setState(425); funcref(); } break; @@ -2790,64 +2772,64 @@ class PainlessParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(446); + setState(441); switch (_input.LA(1)) { case TYPE: case ID: { - setState(433); + setState(428); lamtype(); } break; case LP: { - setState(434); + setState(429); match(LP); - setState(443); + setState(438); _la = _input.LA(1); if (_la==TYPE || _la==ID) { { - setState(435); + setState(430); lamtype(); - setState(440); + setState(435); _errHandler.sync(this); _la = _input.LA(1); while (_la==COMMA) { { { - setState(436); + setState(431); match(COMMA); - setState(437); + setState(432); lamtype(); } } - setState(442); + setState(437); _errHandler.sync(this); _la = _input.LA(1); } } } - setState(445); + setState(440); match(RP); } break; default: throw new NoViableAltException(this); } - setState(448); + setState(443); match(ARROW); - setState(451); - switch ( getInterpreter().adaptivePredict(_input,38,_ctx) ) { + setState(446); + switch ( getInterpreter().adaptivePredict(_input,37,_ctx) ) { case 1: { - setState(449); + setState(444); block(); } break; case 2: { - setState(450); + setState(445); expression(0); } break; @@ -2888,16 +2870,16 @@ class PainlessParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(454); + setState(449); _la = _input.LA(1); if (_la==TYPE) { { - setState(453); + setState(448); decltype(); } } - setState(456); + setState(451); match(ID); } } @@ -2940,33 +2922,33 @@ class PainlessParser extends Parser { FuncrefContext _localctx = new FuncrefContext(_ctx, getState()); enterRule(_localctx, 50, RULE_funcref); try { - setState(462); - switch ( getInterpreter().adaptivePredict(_input,40,_ctx) ) { + setState(457); + switch ( getInterpreter().adaptivePredict(_input,39,_ctx) ) { case 1: enterOuterAlt(_localctx, 1); { - setState(458); + setState(453); classFuncref(); } break; case 2: enterOuterAlt(_localctx, 2); { - setState(459); + setState(454); constructorFuncref(); } break; case 3: enterOuterAlt(_localctx, 3); { - setState(460); + setState(455); capturingFuncref(); } break; case 4: enterOuterAlt(_localctx, 4); { - setState(461); + setState(456); localFuncref(); } break; @@ -3004,11 +2986,11 @@ class PainlessParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(464); + setState(459); match(TYPE); - setState(465); + setState(460); match(REF); - setState(466); + setState(461); match(ID); } } @@ -3046,11 +3028,11 @@ class PainlessParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(468); + setState(463); decltype(); - setState(469); + setState(464); match(REF); - setState(470); + setState(465); match(NEW); } } @@ -3088,11 +3070,11 @@ class PainlessParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(472); + setState(467); match(ID); - setState(473); + setState(468); match(REF); - setState(474); + setState(469); match(ID); } } @@ -3128,11 +3110,11 @@ class PainlessParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(476); + setState(471); match(THIS); - setState(477); + setState(472); match(REF); - setState(478); + setState(473); match(ID); } } @@ -3239,7 +3221,7 @@ class PainlessParser extends Parser { } public static final String _serializedATN = - "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3R\u01e3\4\2\t\2\4"+ + "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3R\u01de\4\2\t\2\4"+ "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+ "\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+ "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+ @@ -3255,171 +3237,169 @@ class PainlessParser extends Parser { "\16\7\u00bb\13\7\3\7\3\7\3\b\3\b\3\t\3\t\5\t\u00c3\n\t\3\n\3\n\3\13\3"+ "\13\3\13\3\13\7\13\u00cb\n\13\f\13\16\13\u00ce\13\13\3\f\3\f\3\f\7\f\u00d3"+ "\n\f\f\f\16\f\u00d6\13\f\3\r\3\r\3\r\5\r\u00db\n\r\3\16\3\16\3\16\3\16"+ - "\3\16\3\16\3\16\3\17\3\17\3\17\3\17\3\17\5\17\u00e9\n\17\3\20\3\20\3\20"+ - "\3\20\3\20\3\20\3\20\3\20\3\20\5\20\u00f4\n\20\3\20\3\20\3\20\3\20\3\20"+ + "\3\16\3\16\3\16\3\17\3\17\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20"+ + "\5\20\u00ef\n\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20"+ "\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20"+ "\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20"+ "\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20"+ - "\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20"+ - "\3\20\7\20\u0134\n\20\f\20\16\20\u0137\13\20\3\21\3\21\3\21\3\21\3\21"+ + "\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\7\20\u012f\n\20\f\20\16"+ + "\20\u0132\13\20\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21"+ "\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21"+ - "\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\5\21\u0156\n\21\3\22"+ - "\3\22\7\22\u015a\n\22\f\22\16\22\u015d\13\22\3\22\3\22\3\22\7\22\u0162"+ - "\n\22\f\22\16\22\u0165\13\22\3\22\3\22\3\22\3\22\3\22\3\22\6\22\u016d"+ - "\n\22\r\22\16\22\u016e\3\22\3\22\7\22\u0173\n\22\f\22\16\22\u0176\13\22"+ - "\5\22\u0178\n\22\5\22\u017a\n\22\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3"+ - "\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\5\23\u018f"+ - "\n\23\3\24\3\24\3\24\3\24\5\24\u0195\n\24\3\25\3\25\3\25\3\25\3\25\5\25"+ - "\u019c\n\25\3\26\3\26\3\26\3\26\3\27\3\27\3\27\3\27\7\27\u01a6\n\27\f"+ - "\27\16\27\u01a9\13\27\5\27\u01ab\n\27\3\27\3\27\3\30\3\30\3\30\5\30\u01b2"+ - "\n\30\3\31\3\31\3\31\3\31\3\31\7\31\u01b9\n\31\f\31\16\31\u01bc\13\31"+ - "\5\31\u01be\n\31\3\31\5\31\u01c1\n\31\3\31\3\31\3\31\5\31\u01c6\n\31\3"+ - "\32\5\32\u01c9\n\32\3\32\3\32\3\33\3\33\3\33\3\33\5\33\u01d1\n\33\3\34"+ - "\3\34\3\34\3\34\3\35\3\35\3\35\3\35\3\36\3\36\3\36\3\36\3\37\3\37\3\37"+ - "\3\37\3\37\2\3\36 \2\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60"+ - "\62\64\668:<\2\r\3\2:E\3\2\35\37\3\2 !\3\2\66\67\3\2\"$\3\2%(\3\2),\3"+ - "\289\3\2FI\4\2\33\34 !\3\2QR\u0212\2A\3\2\2\2\4L\3\2\2\2\6Q\3\2\2\2\b"+ - "\u00af\3\2\2\2\n\u00b3\3\2\2\2\f\u00b5\3\2\2\2\16\u00be\3\2\2\2\20\u00c2"+ - "\3\2\2\2\22\u00c4\3\2\2\2\24\u00c6\3\2\2\2\26\u00cf\3\2\2\2\30\u00d7\3"+ - "\2\2\2\32\u00dc\3\2\2\2\34\u00e8\3\2\2\2\36\u00f3\3\2\2\2 \u0155\3\2\2"+ - "\2\"\u0179\3\2\2\2$\u018e\3\2\2\2&\u0194\3\2\2\2(\u019b\3\2\2\2*\u019d"+ - "\3\2\2\2,\u01a1\3\2\2\2.\u01b1\3\2\2\2\60\u01c0\3\2\2\2\62\u01c8\3\2\2"+ - "\2\64\u01d0\3\2\2\2\66\u01d2\3\2\2\28\u01d6\3\2\2\2:\u01da\3\2\2\2<\u01de"+ - "\3\2\2\2>@\5\4\3\2?>\3\2\2\2@C\3\2\2\2A?\3\2\2\2AB\3\2\2\2BG\3\2\2\2C"+ - "A\3\2\2\2DF\5\b\5\2ED\3\2\2\2FI\3\2\2\2GE\3\2\2\2GH\3\2\2\2HJ\3\2\2\2"+ - "IG\3\2\2\2JK\7\2\2\3K\3\3\2\2\2LM\5\26\f\2MN\7P\2\2NO\5\6\4\2OP\5\f\7"+ - "\2P\5\3\2\2\2Q]\7\t\2\2RS\5\26\f\2SZ\7P\2\2TU\7\f\2\2UV\5\26\f\2VW\7P"+ - "\2\2WY\3\2\2\2XT\3\2\2\2Y\\\3\2\2\2ZX\3\2\2\2Z[\3\2\2\2[^\3\2\2\2\\Z\3"+ - "\2\2\2]R\3\2\2\2]^\3\2\2\2^_\3\2\2\2_`\7\n\2\2`\7\3\2\2\2ab\7\16\2\2b"+ - "c\7\t\2\2cd\5\36\20\2de\7\n\2\2ei\5\n\6\2fg\7\17\2\2gj\5\n\6\2hj\6\5\2"+ - "\2if\3\2\2\2ih\3\2\2\2j\u00b0\3\2\2\2kl\7\20\2\2lm\7\t\2\2mn\5\36\20\2"+ - "nq\7\n\2\2or\5\n\6\2pr\5\16\b\2qo\3\2\2\2qp\3\2\2\2r\u00b0\3\2\2\2st\7"+ - "\21\2\2tu\5\f\7\2uv\7\20\2\2vw\7\t\2\2wx\5\36\20\2xy\7\n\2\2yz\5\34\17"+ - "\2z\u00b0\3\2\2\2{|\7\22\2\2|~\7\t\2\2}\177\5\20\t\2~}\3\2\2\2~\177\3"+ - "\2\2\2\177\u0080\3\2\2\2\u0080\u0082\7\r\2\2\u0081\u0083\5\36\20\2\u0082"+ - "\u0081\3\2\2\2\u0082\u0083\3\2\2\2\u0083\u0084\3\2\2\2\u0084\u0086\7\r"+ - "\2\2\u0085\u0087\5\22\n\2\u0086\u0085\3\2\2\2\u0086\u0087\3\2\2\2\u0087"+ - "\u0088\3\2\2\2\u0088\u008b\7\n\2\2\u0089\u008c\5\n\6\2\u008a\u008c\5\16"+ - "\b\2\u008b\u0089\3\2\2\2\u008b\u008a\3\2\2\2\u008c\u00b0\3\2\2\2\u008d"+ - "\u008e\7\22\2\2\u008e\u008f\7\t\2\2\u008f\u0090\5\26\f\2\u0090\u0091\7"+ - "P\2\2\u0091\u0092\7\63\2\2\u0092\u0093\5\36\20\2\u0093\u0094\7\n\2\2\u0094"+ - "\u0095\5\n\6\2\u0095\u00b0\3\2\2\2\u0096\u0097\5\24\13\2\u0097\u0098\5"+ - "\34\17\2\u0098\u00b0\3\2\2\2\u0099\u009a\7\23\2\2\u009a\u00b0\5\34\17"+ - "\2\u009b\u009c\7\24\2\2\u009c\u00b0\5\34\17\2\u009d\u009e\7\25\2\2\u009e"+ - "\u009f\5\36\20\2\u009f\u00a0\5\34\17\2\u00a0\u00b0\3\2\2\2\u00a1\u00a2"+ - "\7\27\2\2\u00a2\u00a4\5\f\7\2\u00a3\u00a5\5\32\16\2\u00a4\u00a3\3\2\2"+ - "\2\u00a5\u00a6\3\2\2\2\u00a6\u00a4\3\2\2\2\u00a6\u00a7\3\2\2\2\u00a7\u00b0"+ - "\3\2\2\2\u00a8\u00a9\7\31\2\2\u00a9\u00aa\5\36\20\2\u00aa\u00ab\5\34\17"+ - "\2\u00ab\u00b0\3\2\2\2\u00ac\u00ad\5\36\20\2\u00ad\u00ae\5\34\17\2\u00ae"+ - "\u00b0\3\2\2\2\u00afa\3\2\2\2\u00afk\3\2\2\2\u00afs\3\2\2\2\u00af{\3\2"+ - "\2\2\u00af\u008d\3\2\2\2\u00af\u0096\3\2\2\2\u00af\u0099\3\2\2\2\u00af"+ - "\u009b\3\2\2\2\u00af\u009d\3\2\2\2\u00af\u00a1\3\2\2\2\u00af\u00a8\3\2"+ - "\2\2\u00af\u00ac\3\2\2\2\u00b0\t\3\2\2\2\u00b1\u00b4\5\f\7\2\u00b2\u00b4"+ - "\5\b\5\2\u00b3\u00b1\3\2\2\2\u00b3\u00b2\3\2\2\2\u00b4\13\3\2\2\2\u00b5"+ - "\u00b9\7\5\2\2\u00b6\u00b8\5\b\5\2\u00b7\u00b6\3\2\2\2\u00b8\u00bb\3\2"+ - "\2\2\u00b9\u00b7\3\2\2\2\u00b9\u00ba\3\2\2\2\u00ba\u00bc\3\2\2\2\u00bb"+ - "\u00b9\3\2\2\2\u00bc\u00bd\7\6\2\2\u00bd\r\3\2\2\2\u00be\u00bf\7\r\2\2"+ - "\u00bf\17\3\2\2\2\u00c0\u00c3\5\24\13\2\u00c1\u00c3\5\36\20\2\u00c2\u00c0"+ - "\3\2\2\2\u00c2\u00c1\3\2\2\2\u00c3\21\3\2\2\2\u00c4\u00c5\5\36\20\2\u00c5"+ - "\23\3\2\2\2\u00c6\u00c7\5\26\f\2\u00c7\u00cc\5\30\r\2\u00c8\u00c9\7\f"+ - "\2\2\u00c9\u00cb\5\30\r\2\u00ca\u00c8\3\2\2\2\u00cb\u00ce\3\2\2\2\u00cc"+ - "\u00ca\3\2\2\2\u00cc\u00cd\3\2\2\2\u00cd\25\3\2\2\2\u00ce\u00cc\3\2\2"+ - "\2\u00cf\u00d4\7O\2\2\u00d0\u00d1\7\7\2\2\u00d1\u00d3\7\b\2\2\u00d2\u00d0"+ - "\3\2\2\2\u00d3\u00d6\3\2\2\2\u00d4\u00d2\3\2\2\2\u00d4\u00d5\3\2\2\2\u00d5"+ - "\27\3\2\2\2\u00d6\u00d4\3\2\2\2\u00d7\u00da\7P\2\2\u00d8\u00d9\7:\2\2"+ - "\u00d9\u00db\5\36\20\2\u00da\u00d8\3\2\2\2\u00da\u00db\3\2\2\2\u00db\31"+ - "\3\2\2\2\u00dc\u00dd\7\30\2\2\u00dd\u00de\7\t\2\2\u00de\u00df\7O\2\2\u00df"+ - "\u00e0\7P\2\2\u00e0\u00e1\7\n\2\2\u00e1\u00e2\5\f\7\2\u00e2\33\3\2\2\2"+ - "\u00e3\u00e9\7\r\2\2\u00e4\u00e9\7\2\2\3\u00e5\u00e6\b\17\1\2\u00e6\u00e7"+ - "\7\6\2\2\u00e7\u00e9\b\17\1\2\u00e8\u00e3\3\2\2\2\u00e8\u00e4\3\2\2\2"+ - "\u00e8\u00e5\3\2\2\2\u00e9\35\3\2\2\2\u00ea\u00eb\b\20\1\2\u00eb\u00ec"+ - "\5\"\22\2\u00ec\u00ed\t\2\2\2\u00ed\u00ee\5\36\20\3\u00ee\u00ef\b\20\1"+ - "\2\u00ef\u00f4\3\2\2\2\u00f0\u00f1\5 \21\2\u00f1\u00f2\b\20\1\2\u00f2"+ - "\u00f4\3\2\2\2\u00f3\u00ea\3\2\2\2\u00f3\u00f0\3\2\2\2\u00f4\u0135\3\2"+ - "\2\2\u00f5\u00f6\f\17\2\2\u00f6\u00f7\t\3\2\2\u00f7\u00f8\5\36\20\20\u00f8"+ - "\u00f9\b\20\1\2\u00f9\u0134\3\2\2\2\u00fa\u00fb\f\16\2\2\u00fb\u00fc\t"+ - "\4\2\2\u00fc\u00fd\5\36\20\17\u00fd\u00fe\b\20\1\2\u00fe\u0134\3\2\2\2"+ - "\u00ff\u0100\f\r\2\2\u0100\u0101\t\5\2\2\u0101\u0102\5\36\20\16\u0102"+ - "\u0103\b\20\1\2\u0103\u0134\3\2\2\2\u0104\u0105\f\f\2\2\u0105\u0106\t"+ - "\6\2\2\u0106\u0107\5\36\20\r\u0107\u0108\b\20\1\2\u0108\u0134\3\2\2\2"+ - "\u0109\u010a\f\13\2\2\u010a\u010b\t\7\2\2\u010b\u010c\5\36\20\f\u010c"+ - "\u010d\b\20\1\2\u010d\u0134\3\2\2\2\u010e\u010f\f\n\2\2\u010f\u0110\t"+ - "\b\2\2\u0110\u0111\5\36\20\13\u0111\u0112\b\20\1\2\u0112\u0134\3\2\2\2"+ - "\u0113\u0114\f\t\2\2\u0114\u0115\7-\2\2\u0115\u0116\5\36\20\n\u0116\u0117"+ - "\b\20\1\2\u0117\u0134\3\2\2\2\u0118\u0119\f\b\2\2\u0119\u011a\7.\2\2\u011a"+ - "\u011b\5\36\20\t\u011b\u011c\b\20\1\2\u011c\u0134\3\2\2\2\u011d\u011e"+ - "\f\7\2\2\u011e\u011f\7/\2\2\u011f\u0120\5\36\20\b\u0120\u0121\b\20\1\2"+ - "\u0121\u0134\3\2\2\2\u0122\u0123\f\6\2\2\u0123\u0124\7\60\2\2\u0124\u0125"+ - "\5\36\20\7\u0125\u0126\b\20\1\2\u0126\u0134\3\2\2\2\u0127\u0128\f\5\2"+ - "\2\u0128\u0129\7\61\2\2\u0129\u012a\5\36\20\6\u012a\u012b\b\20\1\2\u012b"+ - "\u0134\3\2\2\2\u012c\u012d\f\4\2\2\u012d\u012e\7\62\2\2\u012e\u012f\5"+ - "\36\20\2\u012f\u0130\7\63\2\2\u0130\u0131\5\36\20\4\u0131\u0132\b\20\1"+ - "\2\u0132\u0134\3\2\2\2\u0133\u00f5\3\2\2\2\u0133\u00fa\3\2\2\2\u0133\u00ff"+ - "\3\2\2\2\u0133\u0104\3\2\2\2\u0133\u0109\3\2\2\2\u0133\u010e\3\2\2\2\u0133"+ - "\u0113\3\2\2\2\u0133\u0118\3\2\2\2\u0133\u011d\3\2\2\2\u0133\u0122\3\2"+ - "\2\2\u0133\u0127\3\2\2\2\u0133\u012c\3\2\2\2\u0134\u0137\3\2\2\2\u0135"+ - "\u0133\3\2\2\2\u0135\u0136\3\2\2\2\u0136\37\3\2\2\2\u0137\u0135\3\2\2"+ - "\2\u0138\u0139\6\21\17\3\u0139\u013a\t\t\2\2\u013a\u0156\5\"\22\2\u013b"+ - "\u013c\6\21\20\3\u013c\u013d\5\"\22\2\u013d\u013e\t\t\2\2\u013e\u0156"+ - "\3\2\2\2\u013f\u0140\6\21\21\3\u0140\u0156\5\"\22\2\u0141\u0142\6\21\22"+ - "\3\u0142\u0143\t\n\2\2\u0143\u0156\b\21\1\2\u0144\u0145\6\21\23\3\u0145"+ - "\u0146\7L\2\2\u0146\u0156\b\21\1\2\u0147\u0148\6\21\24\3\u0148\u0149\7"+ - "M\2\2\u0149\u0156\b\21\1\2\u014a\u014b\6\21\25\3\u014b\u014c\7N\2\2\u014c"+ - "\u0156\b\21\1\2\u014d\u014e\6\21\26\3\u014e\u014f\t\13\2\2\u014f\u0156"+ - "\5 \21\2\u0150\u0151\7\t\2\2\u0151\u0152\5\26\f\2\u0152\u0153\7\n\2\2"+ - "\u0153\u0154\5 \21\2\u0154\u0156\3\2\2\2\u0155\u0138\3\2\2\2\u0155\u013b"+ - "\3\2\2\2\u0155\u013f\3\2\2\2\u0155\u0141\3\2\2\2\u0155\u0144\3\2\2\2\u0155"+ - "\u0147\3\2\2\2\u0155\u014a\3\2\2\2\u0155\u014d\3\2\2\2\u0155\u0150\3\2"+ - "\2\2\u0156!\3\2\2\2\u0157\u015b\5$\23\2\u0158\u015a\5&\24\2\u0159\u0158"+ - "\3\2\2\2\u015a\u015d\3\2\2\2\u015b\u0159\3\2\2\2\u015b\u015c\3\2\2\2\u015c"+ - "\u017a\3\2\2\2\u015d\u015b\3\2\2\2\u015e\u015f\5\26\f\2\u015f\u0163\5"+ - "(\25\2\u0160\u0162\5&\24\2\u0161\u0160\3\2\2\2\u0162\u0165\3\2\2\2\u0163"+ - "\u0161\3\2\2\2\u0163\u0164\3\2\2\2\u0164\u017a\3\2\2\2\u0165\u0163\3\2"+ - "\2\2\u0166\u0167\7\26\2\2\u0167\u016c\7O\2\2\u0168\u0169\7\7\2\2\u0169"+ - "\u016a\5\36\20\2\u016a\u016b\7\b\2\2\u016b\u016d\3\2\2\2\u016c\u0168\3"+ - "\2\2\2\u016d\u016e\3\2\2\2\u016e\u016c\3\2\2\2\u016e\u016f\3\2\2\2\u016f"+ - "\u0177\3\2\2\2\u0170\u0174\5(\25\2\u0171\u0173\5&\24\2\u0172\u0171\3\2"+ - "\2\2\u0173\u0176\3\2\2\2\u0174\u0172\3\2\2\2\u0174\u0175\3\2\2\2\u0175"+ - "\u0178\3\2\2\2\u0176\u0174\3\2\2\2\u0177\u0170\3\2\2\2\u0177\u0178\3\2"+ - "\2\2\u0178\u017a\3\2\2\2\u0179\u0157\3\2\2\2\u0179\u015e\3\2\2\2\u0179"+ - "\u0166\3\2\2\2\u017a#\3\2\2\2\u017b\u017c\6\23\27\3\u017c\u017d\7\t\2"+ - "\2\u017d\u017e\5\36\20\2\u017e\u017f\7\n\2\2\u017f\u0180\b\23\1\2\u0180"+ - "\u018f\3\2\2\2\u0181\u0182\6\23\30\3\u0182\u0183\7\t\2\2\u0183\u0184\5"+ - " \21\2\u0184\u0185\7\n\2\2\u0185\u018f\3\2\2\2\u0186\u018f\7J\2\2\u0187"+ - "\u018f\7K\2\2\u0188\u018f\7P\2\2\u0189\u018a\7P\2\2\u018a\u018f\5,\27"+ - "\2\u018b\u018c\7\26\2\2\u018c\u018d\7O\2\2\u018d\u018f\5,\27\2\u018e\u017b"+ - "\3\2\2\2\u018e\u0181\3\2\2\2\u018e\u0186\3\2\2\2\u018e\u0187\3\2\2\2\u018e"+ - "\u0188\3\2\2\2\u018e\u0189\3\2\2\2\u018e\u018b\3\2\2\2\u018f%\3\2\2\2"+ - "\u0190\u0191\6\24\31\3\u0191\u0195\5(\25\2\u0192\u0193\6\24\32\3\u0193"+ - "\u0195\5*\26\2\u0194\u0190\3\2\2\2\u0194\u0192\3\2\2\2\u0195\'\3\2\2\2"+ - "\u0196\u0197\7\13\2\2\u0197\u0198\7R\2\2\u0198\u019c\5,\27\2\u0199\u019a"+ - "\7\13\2\2\u019a\u019c\t\f\2\2\u019b\u0196\3\2\2\2\u019b\u0199\3\2\2\2"+ - "\u019c)\3\2\2\2\u019d\u019e\7\7\2\2\u019e\u019f\5\36\20\2\u019f\u01a0"+ - "\7\b\2\2\u01a0+\3\2\2\2\u01a1\u01aa\7\t\2\2\u01a2\u01a7\5.\30\2\u01a3"+ - "\u01a4\7\f\2\2\u01a4\u01a6\5.\30\2\u01a5\u01a3\3\2\2\2\u01a6\u01a9\3\2"+ - "\2\2\u01a7\u01a5\3\2\2\2\u01a7\u01a8\3\2\2\2\u01a8\u01ab\3\2\2\2\u01a9"+ - "\u01a7\3\2\2\2\u01aa\u01a2\3\2\2\2\u01aa\u01ab\3\2\2\2\u01ab\u01ac\3\2"+ - "\2\2\u01ac\u01ad\7\n\2\2\u01ad-\3\2\2\2\u01ae\u01b2\5\36\20\2\u01af\u01b2"+ - "\5\60\31\2\u01b0\u01b2\5\64\33\2\u01b1\u01ae\3\2\2\2\u01b1\u01af\3\2\2"+ - "\2\u01b1\u01b0\3\2\2\2\u01b2/\3\2\2\2\u01b3\u01c1\5\62\32\2\u01b4\u01bd"+ - "\7\t\2\2\u01b5\u01ba\5\62\32\2\u01b6\u01b7\7\f\2\2\u01b7\u01b9\5\62\32"+ - "\2\u01b8\u01b6\3\2\2\2\u01b9\u01bc\3\2\2\2\u01ba\u01b8\3\2\2\2\u01ba\u01bb"+ - "\3\2\2\2\u01bb\u01be\3\2\2\2\u01bc\u01ba\3\2\2\2\u01bd\u01b5\3\2\2\2\u01bd"+ - "\u01be\3\2\2\2\u01be\u01bf\3\2\2\2\u01bf\u01c1\7\n\2\2\u01c0\u01b3\3\2"+ - "\2\2\u01c0\u01b4\3\2\2\2\u01c1\u01c2\3\2\2\2\u01c2\u01c5\7\65\2\2\u01c3"+ - "\u01c6\5\f\7\2\u01c4\u01c6\5\36\20\2\u01c5\u01c3\3\2\2\2\u01c5\u01c4\3"+ - "\2\2\2\u01c6\61\3\2\2\2\u01c7\u01c9\5\26\f\2\u01c8\u01c7\3\2\2\2\u01c8"+ - "\u01c9\3\2\2\2\u01c9\u01ca\3\2\2\2\u01ca\u01cb\7P\2\2\u01cb\63\3\2\2\2"+ - "\u01cc\u01d1\5\66\34\2\u01cd\u01d1\58\35\2\u01ce\u01d1\5:\36\2\u01cf\u01d1"+ - "\5<\37\2\u01d0\u01cc\3\2\2\2\u01d0\u01cd\3\2\2\2\u01d0\u01ce\3\2\2\2\u01d0"+ - "\u01cf\3\2\2\2\u01d1\65\3\2\2\2\u01d2\u01d3\7O\2\2\u01d3\u01d4\7\64\2"+ - "\2\u01d4\u01d5\7P\2\2\u01d5\67\3\2\2\2\u01d6\u01d7\5\26\f\2\u01d7\u01d8"+ - "\7\64\2\2\u01d8\u01d9\7\26\2\2\u01d99\3\2\2\2\u01da\u01db\7P\2\2\u01db"+ - "\u01dc\7\64\2\2\u01dc\u01dd\7P\2\2\u01dd;\3\2\2\2\u01de\u01df\7\32\2\2"+ - "\u01df\u01e0\7\64\2\2\u01e0\u01e1\7P\2\2\u01e1=\3\2\2\2+AGZ]iq~\u0082"+ - "\u0086\u008b\u00a6\u00af\u00b3\u00b9\u00c2\u00cc\u00d4\u00da\u00e8\u00f3"+ - "\u0133\u0135\u0155\u015b\u0163\u016e\u0174\u0177\u0179\u018e\u0194\u019b"+ - "\u01a7\u01aa\u01b1\u01ba\u01bd\u01c0\u01c5\u01c8\u01d0"; + "\3\21\3\21\3\21\3\21\5\21\u0151\n\21\3\22\3\22\7\22\u0155\n\22\f\22\16"+ + "\22\u0158\13\22\3\22\3\22\3\22\7\22\u015d\n\22\f\22\16\22\u0160\13\22"+ + "\3\22\3\22\3\22\3\22\3\22\3\22\6\22\u0168\n\22\r\22\16\22\u0169\3\22\3"+ + "\22\7\22\u016e\n\22\f\22\16\22\u0171\13\22\5\22\u0173\n\22\5\22\u0175"+ + "\n\22\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23"+ + "\3\23\3\23\3\23\3\23\3\23\3\23\5\23\u018a\n\23\3\24\3\24\3\24\3\24\5\24"+ + "\u0190\n\24\3\25\3\25\3\25\3\25\3\25\5\25\u0197\n\25\3\26\3\26\3\26\3"+ + "\26\3\27\3\27\3\27\3\27\7\27\u01a1\n\27\f\27\16\27\u01a4\13\27\5\27\u01a6"+ + "\n\27\3\27\3\27\3\30\3\30\3\30\5\30\u01ad\n\30\3\31\3\31\3\31\3\31\3\31"+ + "\7\31\u01b4\n\31\f\31\16\31\u01b7\13\31\5\31\u01b9\n\31\3\31\5\31\u01bc"+ + "\n\31\3\31\3\31\3\31\5\31\u01c1\n\31\3\32\5\32\u01c4\n\32\3\32\3\32\3"+ + "\33\3\33\3\33\3\33\5\33\u01cc\n\33\3\34\3\34\3\34\3\34\3\35\3\35\3\35"+ + "\3\35\3\36\3\36\3\36\3\36\3\37\3\37\3\37\3\37\3\37\2\3\36 \2\4\6\b\n\f"+ + "\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\62\64\668:<\2\16\3\3\r\r\3\2:"+ + "E\3\2\35\37\3\2 !\3\2\66\67\3\2\"$\3\2%(\3\2),\3\289\3\2FI\4\2\33\34 "+ + "!\3\2QR\u020b\2A\3\2\2\2\4L\3\2\2\2\6Q\3\2\2\2\b\u00af\3\2\2\2\n\u00b3"+ + "\3\2\2\2\f\u00b5\3\2\2\2\16\u00be\3\2\2\2\20\u00c2\3\2\2\2\22\u00c4\3"+ + "\2\2\2\24\u00c6\3\2\2\2\26\u00cf\3\2\2\2\30\u00d7\3\2\2\2\32\u00dc\3\2"+ + "\2\2\34\u00e3\3\2\2\2\36\u00ee\3\2\2\2 \u0150\3\2\2\2\"\u0174\3\2\2\2"+ + "$\u0189\3\2\2\2&\u018f\3\2\2\2(\u0196\3\2\2\2*\u0198\3\2\2\2,\u019c\3"+ + "\2\2\2.\u01ac\3\2\2\2\60\u01bb\3\2\2\2\62\u01c3\3\2\2\2\64\u01cb\3\2\2"+ + "\2\66\u01cd\3\2\2\28\u01d1\3\2\2\2:\u01d5\3\2\2\2<\u01d9\3\2\2\2>@\5\4"+ + "\3\2?>\3\2\2\2@C\3\2\2\2A?\3\2\2\2AB\3\2\2\2BG\3\2\2\2CA\3\2\2\2DF\5\b"+ + "\5\2ED\3\2\2\2FI\3\2\2\2GE\3\2\2\2GH\3\2\2\2HJ\3\2\2\2IG\3\2\2\2JK\7\2"+ + "\2\3K\3\3\2\2\2LM\5\26\f\2MN\7P\2\2NO\5\6\4\2OP\5\f\7\2P\5\3\2\2\2Q]\7"+ + "\t\2\2RS\5\26\f\2SZ\7P\2\2TU\7\f\2\2UV\5\26\f\2VW\7P\2\2WY\3\2\2\2XT\3"+ + "\2\2\2Y\\\3\2\2\2ZX\3\2\2\2Z[\3\2\2\2[^\3\2\2\2\\Z\3\2\2\2]R\3\2\2\2]"+ + "^\3\2\2\2^_\3\2\2\2_`\7\n\2\2`\7\3\2\2\2ab\7\16\2\2bc\7\t\2\2cd\5\36\20"+ + "\2de\7\n\2\2ei\5\n\6\2fg\7\17\2\2gj\5\n\6\2hj\6\5\2\2if\3\2\2\2ih\3\2"+ + "\2\2j\u00b0\3\2\2\2kl\7\20\2\2lm\7\t\2\2mn\5\36\20\2nq\7\n\2\2or\5\n\6"+ + "\2pr\5\16\b\2qo\3\2\2\2qp\3\2\2\2r\u00b0\3\2\2\2st\7\21\2\2tu\5\f\7\2"+ + "uv\7\20\2\2vw\7\t\2\2wx\5\36\20\2xy\7\n\2\2yz\5\34\17\2z\u00b0\3\2\2\2"+ + "{|\7\22\2\2|~\7\t\2\2}\177\5\20\t\2~}\3\2\2\2~\177\3\2\2\2\177\u0080\3"+ + "\2\2\2\u0080\u0082\7\r\2\2\u0081\u0083\5\36\20\2\u0082\u0081\3\2\2\2\u0082"+ + "\u0083\3\2\2\2\u0083\u0084\3\2\2\2\u0084\u0086\7\r\2\2\u0085\u0087\5\22"+ + "\n\2\u0086\u0085\3\2\2\2\u0086\u0087\3\2\2\2\u0087\u0088\3\2\2\2\u0088"+ + "\u008b\7\n\2\2\u0089\u008c\5\n\6\2\u008a\u008c\5\16\b\2\u008b\u0089\3"+ + "\2\2\2\u008b\u008a\3\2\2\2\u008c\u00b0\3\2\2\2\u008d\u008e\7\22\2\2\u008e"+ + "\u008f\7\t\2\2\u008f\u0090\5\26\f\2\u0090\u0091\7P\2\2\u0091\u0092\7\63"+ + "\2\2\u0092\u0093\5\36\20\2\u0093\u0094\7\n\2\2\u0094\u0095\5\n\6\2\u0095"+ + "\u00b0\3\2\2\2\u0096\u0097\5\24\13\2\u0097\u0098\5\34\17\2\u0098\u00b0"+ + "\3\2\2\2\u0099\u009a\7\23\2\2\u009a\u00b0\5\34\17\2\u009b\u009c\7\24\2"+ + "\2\u009c\u00b0\5\34\17\2\u009d\u009e\7\25\2\2\u009e\u009f\5\36\20\2\u009f"+ + "\u00a0\5\34\17\2\u00a0\u00b0\3\2\2\2\u00a1\u00a2\7\27\2\2\u00a2\u00a4"+ + "\5\f\7\2\u00a3\u00a5\5\32\16\2\u00a4\u00a3\3\2\2\2\u00a5\u00a6\3\2\2\2"+ + "\u00a6\u00a4\3\2\2\2\u00a6\u00a7\3\2\2\2\u00a7\u00b0\3\2\2\2\u00a8\u00a9"+ + "\7\31\2\2\u00a9\u00aa\5\36\20\2\u00aa\u00ab\5\34\17\2\u00ab\u00b0\3\2"+ + "\2\2\u00ac\u00ad\5\36\20\2\u00ad\u00ae\5\34\17\2\u00ae\u00b0\3\2\2\2\u00af"+ + "a\3\2\2\2\u00afk\3\2\2\2\u00afs\3\2\2\2\u00af{\3\2\2\2\u00af\u008d\3\2"+ + "\2\2\u00af\u0096\3\2\2\2\u00af\u0099\3\2\2\2\u00af\u009b\3\2\2\2\u00af"+ + "\u009d\3\2\2\2\u00af\u00a1\3\2\2\2\u00af\u00a8\3\2\2\2\u00af\u00ac\3\2"+ + "\2\2\u00b0\t\3\2\2\2\u00b1\u00b4\5\f\7\2\u00b2\u00b4\5\b\5\2\u00b3\u00b1"+ + "\3\2\2\2\u00b3\u00b2\3\2\2\2\u00b4\13\3\2\2\2\u00b5\u00b9\7\5\2\2\u00b6"+ + "\u00b8\5\b\5\2\u00b7\u00b6\3\2\2\2\u00b8\u00bb\3\2\2\2\u00b9\u00b7\3\2"+ + "\2\2\u00b9\u00ba\3\2\2\2\u00ba\u00bc\3\2\2\2\u00bb\u00b9\3\2\2\2\u00bc"+ + "\u00bd\7\6\2\2\u00bd\r\3\2\2\2\u00be\u00bf\7\r\2\2\u00bf\17\3\2\2\2\u00c0"+ + "\u00c3\5\24\13\2\u00c1\u00c3\5\36\20\2\u00c2\u00c0\3\2\2\2\u00c2\u00c1"+ + "\3\2\2\2\u00c3\21\3\2\2\2\u00c4\u00c5\5\36\20\2\u00c5\23\3\2\2\2\u00c6"+ + "\u00c7\5\26\f\2\u00c7\u00cc\5\30\r\2\u00c8\u00c9\7\f\2\2\u00c9\u00cb\5"+ + "\30\r\2\u00ca\u00c8\3\2\2\2\u00cb\u00ce\3\2\2\2\u00cc\u00ca\3\2\2\2\u00cc"+ + "\u00cd\3\2\2\2\u00cd\25\3\2\2\2\u00ce\u00cc\3\2\2\2\u00cf\u00d4\7O\2\2"+ + "\u00d0\u00d1\7\7\2\2\u00d1\u00d3\7\b\2\2\u00d2\u00d0\3\2\2\2\u00d3\u00d6"+ + "\3\2\2\2\u00d4\u00d2\3\2\2\2\u00d4\u00d5\3\2\2\2\u00d5\27\3\2\2\2\u00d6"+ + "\u00d4\3\2\2\2\u00d7\u00da\7P\2\2\u00d8\u00d9\7:\2\2\u00d9\u00db\5\36"+ + "\20\2\u00da\u00d8\3\2\2\2\u00da\u00db\3\2\2\2\u00db\31\3\2\2\2\u00dc\u00dd"+ + "\7\30\2\2\u00dd\u00de\7\t\2\2\u00de\u00df\7O\2\2\u00df\u00e0\7P\2\2\u00e0"+ + "\u00e1\7\n\2\2\u00e1\u00e2\5\f\7\2\u00e2\33\3\2\2\2\u00e3\u00e4\t\2\2"+ + "\2\u00e4\35\3\2\2\2\u00e5\u00e6\b\20\1\2\u00e6\u00e7\5\"\22\2\u00e7\u00e8"+ + "\t\3\2\2\u00e8\u00e9\5\36\20\3\u00e9\u00ea\b\20\1\2\u00ea\u00ef\3\2\2"+ + "\2\u00eb\u00ec\5 \21\2\u00ec\u00ed\b\20\1\2\u00ed\u00ef\3\2\2\2\u00ee"+ + "\u00e5\3\2\2\2\u00ee\u00eb\3\2\2\2\u00ef\u0130\3\2\2\2\u00f0\u00f1\f\17"+ + "\2\2\u00f1\u00f2\t\4\2\2\u00f2\u00f3\5\36\20\20\u00f3\u00f4\b\20\1\2\u00f4"+ + "\u012f\3\2\2\2\u00f5\u00f6\f\16\2\2\u00f6\u00f7\t\5\2\2\u00f7\u00f8\5"+ + "\36\20\17\u00f8\u00f9\b\20\1\2\u00f9\u012f\3\2\2\2\u00fa\u00fb\f\r\2\2"+ + "\u00fb\u00fc\t\6\2\2\u00fc\u00fd\5\36\20\16\u00fd\u00fe\b\20\1\2\u00fe"+ + "\u012f\3\2\2\2\u00ff\u0100\f\f\2\2\u0100\u0101\t\7\2\2\u0101\u0102\5\36"+ + "\20\r\u0102\u0103\b\20\1\2\u0103\u012f\3\2\2\2\u0104\u0105\f\13\2\2\u0105"+ + "\u0106\t\b\2\2\u0106\u0107\5\36\20\f\u0107\u0108\b\20\1\2\u0108\u012f"+ + "\3\2\2\2\u0109\u010a\f\n\2\2\u010a\u010b\t\t\2\2\u010b\u010c\5\36\20\13"+ + "\u010c\u010d\b\20\1\2\u010d\u012f\3\2\2\2\u010e\u010f\f\t\2\2\u010f\u0110"+ + "\7-\2\2\u0110\u0111\5\36\20\n\u0111\u0112\b\20\1\2\u0112\u012f\3\2\2\2"+ + "\u0113\u0114\f\b\2\2\u0114\u0115\7.\2\2\u0115\u0116\5\36\20\t\u0116\u0117"+ + "\b\20\1\2\u0117\u012f\3\2\2\2\u0118\u0119\f\7\2\2\u0119\u011a\7/\2\2\u011a"+ + "\u011b\5\36\20\b\u011b\u011c\b\20\1\2\u011c\u012f\3\2\2\2\u011d\u011e"+ + "\f\6\2\2\u011e\u011f\7\60\2\2\u011f\u0120\5\36\20\7\u0120\u0121\b\20\1"+ + "\2\u0121\u012f\3\2\2\2\u0122\u0123\f\5\2\2\u0123\u0124\7\61\2\2\u0124"+ + "\u0125\5\36\20\6\u0125\u0126\b\20\1\2\u0126\u012f\3\2\2\2\u0127\u0128"+ + "\f\4\2\2\u0128\u0129\7\62\2\2\u0129\u012a\5\36\20\2\u012a\u012b\7\63\2"+ + "\2\u012b\u012c\5\36\20\4\u012c\u012d\b\20\1\2\u012d\u012f\3\2\2\2\u012e"+ + "\u00f0\3\2\2\2\u012e\u00f5\3\2\2\2\u012e\u00fa\3\2\2\2\u012e\u00ff\3\2"+ + "\2\2\u012e\u0104\3\2\2\2\u012e\u0109\3\2\2\2\u012e\u010e\3\2\2\2\u012e"+ + "\u0113\3\2\2\2\u012e\u0118\3\2\2\2\u012e\u011d\3\2\2\2\u012e\u0122\3\2"+ + "\2\2\u012e\u0127\3\2\2\2\u012f\u0132\3\2\2\2\u0130\u012e\3\2\2\2\u0130"+ + "\u0131\3\2\2\2\u0131\37\3\2\2\2\u0132\u0130\3\2\2\2\u0133\u0134\6\21\17"+ + "\3\u0134\u0135\t\n\2\2\u0135\u0151\5\"\22\2\u0136\u0137\6\21\20\3\u0137"+ + "\u0138\5\"\22\2\u0138\u0139\t\n\2\2\u0139\u0151\3\2\2\2\u013a\u013b\6"+ + "\21\21\3\u013b\u0151\5\"\22\2\u013c\u013d\6\21\22\3\u013d\u013e\t\13\2"+ + "\2\u013e\u0151\b\21\1\2\u013f\u0140\6\21\23\3\u0140\u0141\7L\2\2\u0141"+ + "\u0151\b\21\1\2\u0142\u0143\6\21\24\3\u0143\u0144\7M\2\2\u0144\u0151\b"+ + "\21\1\2\u0145\u0146\6\21\25\3\u0146\u0147\7N\2\2\u0147\u0151\b\21\1\2"+ + "\u0148\u0149\6\21\26\3\u0149\u014a\t\f\2\2\u014a\u0151\5 \21\2\u014b\u014c"+ + "\7\t\2\2\u014c\u014d\5\26\f\2\u014d\u014e\7\n\2\2\u014e\u014f\5 \21\2"+ + "\u014f\u0151\3\2\2\2\u0150\u0133\3\2\2\2\u0150\u0136\3\2\2\2\u0150\u013a"+ + "\3\2\2\2\u0150\u013c\3\2\2\2\u0150\u013f\3\2\2\2\u0150\u0142\3\2\2\2\u0150"+ + "\u0145\3\2\2\2\u0150\u0148\3\2\2\2\u0150\u014b\3\2\2\2\u0151!\3\2\2\2"+ + "\u0152\u0156\5$\23\2\u0153\u0155\5&\24\2\u0154\u0153\3\2\2\2\u0155\u0158"+ + "\3\2\2\2\u0156\u0154\3\2\2\2\u0156\u0157\3\2\2\2\u0157\u0175\3\2\2\2\u0158"+ + "\u0156\3\2\2\2\u0159\u015a\5\26\f\2\u015a\u015e\5(\25\2\u015b\u015d\5"+ + "&\24\2\u015c\u015b\3\2\2\2\u015d\u0160\3\2\2\2\u015e\u015c\3\2\2\2\u015e"+ + "\u015f\3\2\2\2\u015f\u0175\3\2\2\2\u0160\u015e\3\2\2\2\u0161\u0162\7\26"+ + "\2\2\u0162\u0167\7O\2\2\u0163\u0164\7\7\2\2\u0164\u0165\5\36\20\2\u0165"+ + "\u0166\7\b\2\2\u0166\u0168\3\2\2\2\u0167\u0163\3\2\2\2\u0168\u0169\3\2"+ + "\2\2\u0169\u0167\3\2\2\2\u0169\u016a\3\2\2\2\u016a\u0172\3\2\2\2\u016b"+ + "\u016f\5(\25\2\u016c\u016e\5&\24\2\u016d\u016c\3\2\2\2\u016e\u0171\3\2"+ + "\2\2\u016f\u016d\3\2\2\2\u016f\u0170\3\2\2\2\u0170\u0173\3\2\2\2\u0171"+ + "\u016f\3\2\2\2\u0172\u016b\3\2\2\2\u0172\u0173\3\2\2\2\u0173\u0175\3\2"+ + "\2\2\u0174\u0152\3\2\2\2\u0174\u0159\3\2\2\2\u0174\u0161\3\2\2\2\u0175"+ + "#\3\2\2\2\u0176\u0177\6\23\27\3\u0177\u0178\7\t\2\2\u0178\u0179\5\36\20"+ + "\2\u0179\u017a\7\n\2\2\u017a\u017b\b\23\1\2\u017b\u018a\3\2\2\2\u017c"+ + "\u017d\6\23\30\3\u017d\u017e\7\t\2\2\u017e\u017f\5 \21\2\u017f\u0180\7"+ + "\n\2\2\u0180\u018a\3\2\2\2\u0181\u018a\7J\2\2\u0182\u018a\7K\2\2\u0183"+ + "\u018a\7P\2\2\u0184\u0185\7P\2\2\u0185\u018a\5,\27\2\u0186\u0187\7\26"+ + "\2\2\u0187\u0188\7O\2\2\u0188\u018a\5,\27\2\u0189\u0176\3\2\2\2\u0189"+ + "\u017c\3\2\2\2\u0189\u0181\3\2\2\2\u0189\u0182\3\2\2\2\u0189\u0183\3\2"+ + "\2\2\u0189\u0184\3\2\2\2\u0189\u0186\3\2\2\2\u018a%\3\2\2\2\u018b\u018c"+ + "\6\24\31\3\u018c\u0190\5(\25\2\u018d\u018e\6\24\32\3\u018e\u0190\5*\26"+ + "\2\u018f\u018b\3\2\2\2\u018f\u018d\3\2\2\2\u0190\'\3\2\2\2\u0191\u0192"+ + "\7\13\2\2\u0192\u0193\7R\2\2\u0193\u0197\5,\27\2\u0194\u0195\7\13\2\2"+ + "\u0195\u0197\t\r\2\2\u0196\u0191\3\2\2\2\u0196\u0194\3\2\2\2\u0197)\3"+ + "\2\2\2\u0198\u0199\7\7\2\2\u0199\u019a\5\36\20\2\u019a\u019b\7\b\2\2\u019b"+ + "+\3\2\2\2\u019c\u01a5\7\t\2\2\u019d\u01a2\5.\30\2\u019e\u019f\7\f\2\2"+ + "\u019f\u01a1\5.\30\2\u01a0\u019e\3\2\2\2\u01a1\u01a4\3\2\2\2\u01a2\u01a0"+ + "\3\2\2\2\u01a2\u01a3\3\2\2\2\u01a3\u01a6\3\2\2\2\u01a4\u01a2\3\2\2\2\u01a5"+ + "\u019d\3\2\2\2\u01a5\u01a6\3\2\2\2\u01a6\u01a7\3\2\2\2\u01a7\u01a8\7\n"+ + "\2\2\u01a8-\3\2\2\2\u01a9\u01ad\5\36\20\2\u01aa\u01ad\5\60\31\2\u01ab"+ + "\u01ad\5\64\33\2\u01ac\u01a9\3\2\2\2\u01ac\u01aa\3\2\2\2\u01ac\u01ab\3"+ + "\2\2\2\u01ad/\3\2\2\2\u01ae\u01bc\5\62\32\2\u01af\u01b8\7\t\2\2\u01b0"+ + "\u01b5\5\62\32\2\u01b1\u01b2\7\f\2\2\u01b2\u01b4\5\62\32\2\u01b3\u01b1"+ + "\3\2\2\2\u01b4\u01b7\3\2\2\2\u01b5\u01b3\3\2\2\2\u01b5\u01b6\3\2\2\2\u01b6"+ + "\u01b9\3\2\2\2\u01b7\u01b5\3\2\2\2\u01b8\u01b0\3\2\2\2\u01b8\u01b9\3\2"+ + "\2\2\u01b9\u01ba\3\2\2\2\u01ba\u01bc\7\n\2\2\u01bb\u01ae\3\2\2\2\u01bb"+ + "\u01af\3\2\2\2\u01bc\u01bd\3\2\2\2\u01bd\u01c0\7\65\2\2\u01be\u01c1\5"+ + "\f\7\2\u01bf\u01c1\5\36\20\2\u01c0\u01be\3\2\2\2\u01c0\u01bf\3\2\2\2\u01c1"+ + "\61\3\2\2\2\u01c2\u01c4\5\26\f\2\u01c3\u01c2\3\2\2\2\u01c3\u01c4\3\2\2"+ + "\2\u01c4\u01c5\3\2\2\2\u01c5\u01c6\7P\2\2\u01c6\63\3\2\2\2\u01c7\u01cc"+ + "\5\66\34\2\u01c8\u01cc\58\35\2\u01c9\u01cc\5:\36\2\u01ca\u01cc\5<\37\2"+ + "\u01cb\u01c7\3\2\2\2\u01cb\u01c8\3\2\2\2\u01cb\u01c9\3\2\2\2\u01cb\u01ca"+ + "\3\2\2\2\u01cc\65\3\2\2\2\u01cd\u01ce\7O\2\2\u01ce\u01cf\7\64\2\2\u01cf"+ + "\u01d0\7P\2\2\u01d0\67\3\2\2\2\u01d1\u01d2\5\26\f\2\u01d2\u01d3\7\64\2"+ + "\2\u01d3\u01d4\7\26\2\2\u01d49\3\2\2\2\u01d5\u01d6\7P\2\2\u01d6\u01d7"+ + "\7\64\2\2\u01d7\u01d8\7P\2\2\u01d8;\3\2\2\2\u01d9\u01da\7\32\2\2\u01da"+ + "\u01db\7\64\2\2\u01db\u01dc\7P\2\2\u01dc=\3\2\2\2*AGZ]iq~\u0082\u0086"+ + "\u008b\u00a6\u00af\u00b3\u00b9\u00c2\u00cc\u00d4\u00da\u00ee\u012e\u0130"+ + "\u0150\u0156\u015e\u0169\u016f\u0172\u0174\u0189\u018f\u0196\u01a2\u01a5"+ + "\u01ac\u01b5\u01b8\u01bb\u01c0\u01c3\u01cb"; public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); static { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/SlashStrategy.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/SlashStrategy.java index 720259d5316..698a9dfc364 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/SlashStrategy.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/SlashStrategy.java @@ -20,15 +20,14 @@ package org.elasticsearch.painless.antlr; import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenFactory; /** * Utility to figure out if a {@code /} is division or the start of a regex literal. */ public class SlashStrategy { - public static boolean slashIsRegex(TokenFactory factory) { - StashingTokenFactory stashingFactory = (StashingTokenFactory) factory; - Token lastToken = stashingFactory.getLastToken(); + public static boolean slashIsRegex(PainlessLexer lexer) { + EnhancedPainlessLexer realLexer = (EnhancedPainlessLexer) lexer; + Token lastToken = realLexer.getPreviousToken(); if (lastToken == null) { return true; } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java index 9d2ed2368fe..f3751892b97 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java @@ -183,7 +183,7 @@ public final class Walker extends PainlessParserBaseVisitor { private SourceContext buildAntlrTree(String source) { ANTLRInputStream stream = new ANTLRInputStream(source); - PainlessLexer lexer = new ErrorHandlingLexer(stream, sourceName); + PainlessLexer lexer = new EnhancedPainlessLexer(stream, sourceName); PainlessParser parser = new PainlessParser(new CommonTokenStream(lexer)); ParserErrorStrategy strategy = new ParserErrorStrategy(sourceName); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java index 5001e28a954..dada9a9bc37 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java @@ -79,7 +79,11 @@ public class LambdaTests extends ScriptTestCase { } public void testMultipleStatements() { - assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> { x = x + 1; return x;})")); + assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> { x = x + 1; return x })")); + } + + public void testUnneededCurlyStatements() { + assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> { x + 1 })")); } public void testTwoLambdas() { diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/RegexTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/RegexTests.java index a36eedd7058..e255a776bed 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/RegexTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/RegexTests.java @@ -201,6 +201,6 @@ public class RegexTests extends ScriptTestCase { IllegalArgumentException e = expectScriptThrows(IllegalArgumentException.class, () -> { exec("/asdf/b", emptyMap(), emptyMap(), null); // Not picky so we get a non-assertion error }); - assertEquals("invalid sequence of tokens near ['b'].", e.getMessage()); + assertEquals("unexpected token ['b'] was expecting one of [{, ';'}].", e.getMessage()); } } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/antlr/ParserTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/antlr/ParserTests.java index d1852ada27b..e2bd880b646 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/antlr/ParserTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/antlr/ParserTests.java @@ -40,7 +40,7 @@ public class ParserTests extends ScriptTestCase { private SourceContext buildAntlrTree(String source) { ANTLRInputStream stream = new ANTLRInputStream(source); - PainlessLexer lexer = new ErrorHandlingLexer(stream, "testing"); + PainlessLexer lexer = new EnhancedPainlessLexer(stream, "testing"); PainlessParser parser = new PainlessParser(new CommonTokenStream(lexer)); ParserErrorStrategy strategy = new ParserErrorStrategy("testing"); From e9f2548ee04f75c60b7e6d663a4c5d686aa7dddd Mon Sep 17 00:00:00 2001 From: Jeff Evans Date: Fri, 17 Jun 2016 15:41:25 -0500 Subject: [PATCH 39/87] Include script field even if it value is null Include script field even if it value is null. Closes #16408. --- .../script/ScriptFieldsFetchSubPhase.java | 4 +--- .../messy/tests/SearchFieldsTests.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsFetchSubPhase.java index 0838467bb6c..19a7631ccba 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsFetchSubPhase.java @@ -64,9 +64,7 @@ public final class ScriptFieldsFetchSubPhase implements FetchSubPhase { SearchHitField hitField = hitContext.hit().fields().get(scriptField.name()); if (hitField == null) { final List values; - if (value == null) { - values = Collections.emptyList(); - } else if (value instanceof Collection) { + if (value instanceof Collection) { // TODO: use diamond operator once JI-9019884 is fixed values = new ArrayList<>((Collection) value); } else { diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java index bc604987a70..ba258490119 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java @@ -69,6 +69,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFa import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; @@ -369,6 +370,24 @@ public class SearchFieldsTests extends ESIntegTestCase { assertThat(((Map) sObj2Arr3.get(0)).get("arr3_field1").toString(), equalTo("arr3_value1")); } + public void testScriptFieldsForNullReturn() throws Exception { + client().prepareIndex("test", "type1", "1") + .setSource("foo", "bar") + .setRefresh(true).get(); + + SearchResponse response = client().prepareSearch().setQuery(matchAllQuery()) + .addScriptField("test_script_1", new Script("return null")) + .get(); + + assertNoFailures(response); + + SearchHitField fieldObj = response.getHits().getAt(0).field("test_script_1"); + assertThat(fieldObj, notNullValue()); + List fieldValues = fieldObj.values(); + assertThat(fieldValues, hasSize(1)); + assertThat(fieldValues.get(0), nullValue()); + } + public void testPartialFields() throws Exception { createIndex("test"); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet(); From 084b35c08b2245d01a7c075bbf8e8dec2ea3f110 Mon Sep 17 00:00:00 2001 From: debadair Date: Fri, 17 Jun 2016 14:31:03 -0700 Subject: [PATCH 40/87] Docs: Fixed code callout error. --- .../reference/indices/rollover-index.asciidoc | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/reference/indices/rollover-index.asciidoc b/docs/reference/indices/rollover-index.asciidoc index 6879470267f..194dda80cf8 100644 --- a/docs/reference/indices/rollover-index.asciidoc +++ b/docs/reference/indices/rollover-index.asciidoc @@ -71,11 +71,12 @@ POST my_alias/_rollover/my_new_index_name [float] === Defining the new index -The settings, mappings, and aliases for the new index will be taken from any -matching <>. Additionally, the body of the -request accepts `settings`, `mappings`, and `aliases` just like the -<> API, which will override any values -set in matching index templates: +The settings, mappings, and aliases for the new index are taken from any +matching <>. Additionally, you can specify +`settings`, `mappings`, and `aliases` in the body of the request, just like the +<> API. Values specified in the request +override any values set in matching index templates. For example, the following +`rollover` request overrides the `index.number_of_shards` setting: [source,js] -------------------------------------------------- @@ -92,17 +93,15 @@ POST logs_write/_rollover "max_age": "7d", "max_docs": 1000 }, - "settings": { <1> - "index.number_of_shards": 2 <1> + "settings": { + "index.number_of_shards": 2 } } -------------------------------------------------- // CONSOLE -<1> Set settings to override matching index template, `mappings` and `aliases` - can also be provided. - [float] - === Dry run +[float] +=== Dry run The rollover API supports `dry_run` mode, where request conditions can be checked without performing the actual rollover: From e8826708c170b39713729904ebe5494b5d1d3a76 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 17 Jun 2016 17:40:52 -0400 Subject: [PATCH 41/87] Refactor variables --- .../org/elasticsearch/painless/Compiler.java | 2 +- .../org/elasticsearch/painless/Constant.java | 48 ++ .../org/elasticsearch/painless/Globals.java | 72 +++ .../elasticsearch/painless/LambdaLocals.java | 62 +++ .../org/elasticsearch/painless/Locals.java | 521 ++++++++---------- .../elasticsearch/painless/antlr/Walker.java | 33 +- .../painless/node/AExpression.java | 3 +- .../elasticsearch/painless/node/ALink.java | 7 +- .../painless/node/AStatement.java | 6 +- .../elasticsearch/painless/node/EBinary.java | 21 +- .../elasticsearch/painless/node/EBool.java | 19 +- .../elasticsearch/painless/node/EBoolean.java | 3 +- .../painless/node/ECapturingFunctionRef.java | 21 +- .../elasticsearch/painless/node/ECast.java | 5 +- .../elasticsearch/painless/node/EChain.java | 23 +- .../elasticsearch/painless/node/EComp.java | 7 +- .../painless/node/EConditional.java | 9 +- .../painless/node/EConstant.java | 3 +- .../elasticsearch/painless/node/EDecimal.java | 3 +- .../painless/node/EExplicit.java | 3 +- .../painless/node/EFunctionRef.java | 15 +- .../elasticsearch/painless/node/ELambda.java | 55 +- .../elasticsearch/painless/node/ENull.java | 3 +- .../elasticsearch/painless/node/ENumeric.java | 3 +- .../elasticsearch/painless/node/EUnary.java | 9 +- .../elasticsearch/painless/node/ILambda.java | 40 ++ .../painless/node/LArrayLength.java | 7 +- .../elasticsearch/painless/node/LBrace.java | 9 +- .../painless/node/LCallInvoke.java | 9 +- .../painless/node/LCallLocal.java | 9 +- .../elasticsearch/painless/node/LCast.java | 7 +- .../painless/node/LDefArray.java | 9 +- .../elasticsearch/painless/node/LDefCall.java | 28 +- .../painless/node/LDefField.java | 7 +- .../elasticsearch/painless/node/LField.java | 7 +- .../painless/node/LListShortcut.java | 9 +- .../painless/node/LMapShortcut.java | 9 +- .../painless/node/LNewArray.java | 9 +- .../elasticsearch/painless/node/LNewObj.java | 9 +- .../elasticsearch/painless/node/LRegex.java | 12 +- .../painless/node/LShortcut.java | 7 +- .../elasticsearch/painless/node/LStatic.java | 7 +- .../elasticsearch/painless/node/LString.java | 7 +- .../painless/node/LVariable.java | 16 +- .../elasticsearch/painless/node/SBlock.java | 5 +- .../elasticsearch/painless/node/SBreak.java | 3 +- .../elasticsearch/painless/node/SCatch.java | 9 +- .../painless/node/SContinue.java | 3 +- .../painless/node/SDeclBlock.java | 5 +- .../painless/node/SDeclaration.java | 9 +- .../org/elasticsearch/painless/node/SDo.java | 17 +- .../elasticsearch/painless/node/SEach.java | 59 +- .../painless/node/SExpression.java | 5 +- .../org/elasticsearch/painless/node/SFor.java | 25 +- .../painless/node/SFunction.java | 81 ++- .../org/elasticsearch/painless/node/SIf.java | 11 +- .../elasticsearch/painless/node/SIfElse.java | 17 +- .../elasticsearch/painless/node/SReturn.java | 5 +- .../elasticsearch/painless/node/SSource.java | 134 +++-- .../elasticsearch/painless/node/SThrow.java | 5 +- .../org/elasticsearch/painless/node/STry.java | 15 +- .../elasticsearch/painless/node/SWhile.java | 19 +- .../painless/ReservedWordTests.java | 8 +- 63 files changed, 977 insertions(+), 631 deletions(-) create mode 100644 modules/lang-painless/src/main/java/org/elasticsearch/painless/Constant.java create mode 100644 modules/lang-painless/src/main/java/org/elasticsearch/painless/Globals.java create mode 100644 modules/lang-painless/src/main/java/org/elasticsearch/painless/LambdaLocals.java create mode 100644 modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ILambda.java diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java index 664c567091c..b81a9dee24c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java @@ -109,7 +109,7 @@ final class Compiler { java.lang.reflect.Constructor constructor = clazz.getConstructor(String.class, String.class, BitSet.class); - return constructor.newInstance(name, source, root.getExpressions()); + return constructor.newInstance(name, source, root.getStatements()); } catch (Exception exception) { // Catch everything to let the user know this is something caused internally. throw new IllegalStateException("An internal error occurred attempting to define the script [" + name + "].", exception); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Constant.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Constant.java new file mode 100644 index 00000000000..d42c267fc3f --- /dev/null +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Constant.java @@ -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.painless; + +import java.util.function.Consumer; + +/** + * A constant initializer to be added to the class file. + */ +public class Constant { + public final Location location; + public final String name; + public final org.objectweb.asm.Type type; + public final Consumer initializer; + + /** + * Create a new constant. + * + * @param location the location in the script that is creating it + * @param type the type of the constant + * @param name the name of the constant + * @param initializer code to initialize the constant. It will be called when generating the clinit method and is expected to leave the + * value of the constant on the stack. Generating the load instruction is managed by the caller. + */ + public Constant(Location location, org.objectweb.asm.Type type, String name, Consumer initializer) { + this.location = location; + this.name = name; + this.type = type; + this.initializer = initializer; + } +} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Globals.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Globals.java new file mode 100644 index 00000000000..83eb74d827f --- /dev/null +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Globals.java @@ -0,0 +1,72 @@ +/* + * 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.painless; + +import org.elasticsearch.painless.node.SFunction; + +import java.util.BitSet; +import java.util.HashMap; +import java.util.Map; + +/** + * Program-wide globals (initializers, synthetic methods, etc) + */ +public class Globals { + private final Map syntheticMethods = new HashMap<>(); + private final Map constantInitializers = new HashMap<>(); + private final BitSet statements; + + /** Create a new Globals from the set of statement boundaries */ + public Globals(BitSet statements) { + this.statements = statements; + } + + /** Adds a new synthetic method to be written. It must be analyzed! */ + public void addSyntheticMethod(SFunction function) { + if (!function.synthetic) { + throw new IllegalStateException("method: " + function.name + " is not synthetic"); + } + if (syntheticMethods.put(function.name, function) != null) { + throw new IllegalStateException("synthetic method: " + function.name + " already exists"); + } + } + + /** Adds a new constant initializer to be written */ + public void addConstantInitializer(Constant constant) { + if (constantInitializers.put(constant.name, constant) != null) { + throw new IllegalStateException("constant initializer: " + constant.name + " already exists"); + } + } + + /** Returns the current synthetic methods */ + public Map getSyntheticMethods() { + return syntheticMethods; + } + + /** Returns the current initializers */ + public Map getConstantInitializers() { + return constantInitializers; + } + + /** Returns the set of statement boundaries */ + public BitSet getStatements() { + return statements; + } +} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/LambdaLocals.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/LambdaLocals.java new file mode 100644 index 00000000000..9c01bc4c628 --- /dev/null +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/LambdaLocals.java @@ -0,0 +1,62 @@ +/* + * 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.painless; + +import org.elasticsearch.painless.Definition.Type; + +import java.util.List; +import java.util.Objects; + +/** Extension of locals for lambdas */ +// Note: this isn't functional yet, it throws UOE +// TODO: implement slot renumbering for captures. +class LambdaLocals extends Locals { + private List captures; + + LambdaLocals(Locals parent, List parameters, List captures) { + super(parent); + for (Parameter parameter : parameters) { + defineVariable(parameter.location, parameter.type, parameter.name, false); + } + this.captures = Objects.requireNonNull(captures); + } + + @Override + public Variable getVariable(Location location, String name) { + Variable variable = lookupVariable(location, name); + if (variable != null) { + return variable; + } + if (getParent() != null) { + variable = getParent().getVariable(location, name); + if (variable != null) { + assert captures != null; // unused right now + // make it read-only, and record that it was used. + throw new UnsupportedOperationException("lambda capture is not supported"); + } + } + throw location.createError(new IllegalArgumentException("Variable [" + name + "] is not defined.")); + } + + @Override + public Type getReturnType() { + return Definition.DEF_TYPE; + } +} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java index 30f15c42dde..8cb99ed2404 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java @@ -23,141 +23,273 @@ import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.MethodKey; import org.elasticsearch.painless.Definition.Type; -import java.util.ArrayDeque; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Deque; import java.util.HashMap; -import java.util.Iterator; +import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.function.Consumer; +import java.util.Set; /** * Tracks user defined methods and variables across compilation phases. */ -public final class Locals { +public class Locals { + + /** Reserved word: params map parameter */ + public static final String PARAMS = "params"; + /** Reserved word: Lucene scorer parameter */ + public static final String SCORER = "#scorer"; + /** Reserved word: _value variable for aggregations */ + public static final String VALUE = "_value"; + /** Reserved word: _score variable for search scripts */ + public static final String SCORE = "_score"; + /** Reserved word: ctx map for executable scripts */ + public static final String CTX = "ctx"; + /** Reserved word: loop counter */ + public static final String LOOP = "#loop"; + /** Reserved word: unused */ + public static final String THIS = "#this"; + /** Reserved word: unused */ + public static final String DOC = "doc"; + + /** Map of always reserved keywords */ + public static final Set KEYWORDS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + THIS,PARAMS,SCORER,DOC,VALUE,SCORE,CTX,LOOP + ))); + + /** Creates a new local variable scope (e.g. loop) inside the current scope */ + public static Locals newLocalScope(Locals currentScope) { + return new Locals(currentScope); + } + + /** Creates a new lambda scope inside the current scope */ + public static Locals newLambdaScope(Locals currentScope, List parameters, List captures) { + return new LambdaLocals(currentScope, parameters, captures); + } + + /** Creates a new function scope inside the current scope */ + public static Locals newFunctionScope(Locals programScope, Type returnType, List parameters, int maxLoopCounter) { + Locals locals = new Locals(programScope, returnType); + for (Parameter parameter : parameters) { + locals.defineVariable(parameter.location, parameter.type, parameter.name, false); + } + // Loop counter to catch infinite loops. Internal use only. + if (maxLoopCounter > 0) { + locals.defineVariable(null, Definition.INT_TYPE, LOOP, true); + } + return locals; + } + + /** Creates a new main method scope */ + public static Locals newMainMethodScope(Locals programScope, boolean usesScore, boolean usesCtx, int maxLoopCounter) { + Locals locals = new Locals(programScope, Definition.OBJECT_TYPE); + // This reference. Internal use only. + locals.defineVariable(null, Definition.getType("Object"), THIS, true); + + // Input map of variables passed to the script. + locals.defineVariable(null, Definition.getType("Map"), PARAMS, true); + + // Scorer parameter passed to the script. Internal use only. + locals.defineVariable(null, Definition.DEF_TYPE, SCORER, true); + + // Doc parameter passed to the script. TODO: Currently working as a Map, we can do better? + locals.defineVariable(null, Definition.getType("Map"), DOC, true); + + // Aggregation _value parameter passed to the script. + locals.defineVariable(null, Definition.DEF_TYPE, VALUE, true); + + // Shortcut variables. + + // Document's score as a read-only double. + if (usesScore) { + locals.defineVariable(null, Definition.DOUBLE_TYPE, SCORE, true); + } + + // The ctx map set by executable scripts as a read-only map. + if (usesCtx) { + locals.defineVariable(null, Definition.getType("Map"), CTX, true); + } + + // Loop counter to catch infinite loops. Internal use only. + if (maxLoopCounter > 0) { + locals.defineVariable(null, Definition.INT_TYPE, LOOP, true); + } + return locals; + } + + /** Creates a new program scope: the list of methods. It is the parent for all methods */ + public static Locals newProgramScope(Collection methods) { + Locals locals = new Locals(null, null); + for (Method method : methods) { + locals.addMethod(method); + } + return locals; + } + + /** Checks if a variable exists or not, in this scope or any parents. */ + public final boolean hasVariable(String name) { + Variable variable = lookupVariable(null, name); + if (variable != null) { + return true; + } + if (parent != null) { + return parent.hasVariable(name); + } + return false; + } + + /** Accesses a variable. This will throw IAE if the variable does not exist */ + public Variable getVariable(Location location, String name) { + Variable variable = lookupVariable(location, name); + if (variable != null) { + return variable; + } + if (parent != null) { + return parent.getVariable(location, name); + } + throw location.createError(new IllegalArgumentException("Variable [" + name + "] is not defined.")); + } + + /** Looks up a method. Returns null if the method does not exist. */ + public final Method getMethod(MethodKey key) { + Method method = lookupMethod(key); + if (method != null) { + return method; + } + if (parent != null) { + return parent.getMethod(key); + } + return null; + } + + /** Creates a new variable. Throws IAE if the variable has already been defined (even in a parent) or reserved. */ + public final Variable addVariable(Location location, Type type, String name, boolean readonly) { + if (hasVariable(name)) { + throw location.createError(new IllegalArgumentException("Variable [" + name + "] is already defined.")); + } + if (KEYWORDS.contains(name)) { + throw location.createError(new IllegalArgumentException("Variable [" + name + "] is reserved.")); + } + return defineVariable(location, type, name, readonly); + } + + /** Return type of this scope (e.g. int, if inside a function that returns int) */ + public Type getReturnType() { + return returnType; + } + + /** Returns the top-level program scope. */ + public Locals getProgramScope() { + Locals locals = this; + while (locals.getParent() != null) { + locals = locals.getParent(); + } + return locals; + } + + ///// private impl + + // parent scope + private final Locals parent; + // return type of this scope + private final Type returnType; + // next slot number to assign + int nextSlotNumber; + // variable name -> variable + Map variables; + // method name+arity -> methods + Map methods; /** - * Tracks reserved variables. Must be given to any source of input - * prior to beginning the analysis phase so that reserved variables - * are known ahead of time to assign appropriate slots without - * being wasteful. + * Create a new Locals */ - public interface Reserved { - void markReserved(String name); - boolean isReserved(String name); - - void setMaxLoopCounter(int max); - int getMaxLoopCounter(); + Locals(Locals parent) { + this(parent, parent.getReturnType()); } - - public static final class ExecuteReserved implements Reserved { - public static final String THIS = "#this"; - public static final String PARAMS = "params"; - public static final String SCORER = "#scorer"; - public static final String DOC = "doc"; - public static final String VALUE = "_value"; - public static final String SCORE = "_score"; - public static final String CTX = "ctx"; - public static final String LOOP = "#loop"; - - private boolean score = false; - private boolean ctx = false; - private int maxLoopCounter = 0; - - @Override - public void markReserved(String name) { - if (SCORE.equals(name)) { - score = true; - } else if (CTX.equals(name)) { - ctx = true; - } - } - - @Override - public boolean isReserved(String name) { - return name.equals(THIS) || name.equals(PARAMS) || name.equals(SCORER) || name.equals(DOC) || - name.equals(VALUE) || name.equals(SCORE) || name.equals(CTX) || name.equals(LOOP); - } - - public boolean usesScore() { - return score; - } - - public boolean usesCtx() { - return ctx; - } - - @Override - public void setMaxLoopCounter(int max) { - maxLoopCounter = max; - } - - @Override - public int getMaxLoopCounter() { - return maxLoopCounter; + + /** + * Create a new Locals with specified return type + */ + Locals(Locals parent, Type returnType) { + this.parent = parent; + this.returnType = returnType; + if (parent == null) { + this.nextSlotNumber = 0; + } else { + this.nextSlotNumber = parent.getNextSlot(); } } - public static final class FunctionReserved implements Reserved { - public static final String THIS = "#this"; - public static final String LOOP = "#loop"; + /** Returns the parent scope */ + Locals getParent() { + return parent; + } - private int maxLoopCounter = 0; - - public void markReserved(String name) { - // Do nothing. + /** Looks up a variable at this scope only. Returns null if the variable does not exist. */ + Variable lookupVariable(Location location, String name) { + if (variables == null) { + return null; } + return variables.get(name); + } - public boolean isReserved(String name) { - return name.equals(THIS) || name.equals(LOOP); + /** Looks up a method at this scope only. Returns null if the method does not exist. */ + Method lookupMethod(MethodKey key) { + if (methods == null) { + return null; } + return methods.get(key); + } - @Override - public void setMaxLoopCounter(int max) { - maxLoopCounter = max; + + /** Defines a variable at this scope internally. */ + Variable defineVariable(Location location, Type type, String name, boolean readonly) { + if (variables == null) { + variables = new HashMap<>(); } + Variable variable = new Variable(location, name, type, readonly); + variable.slot = getNextSlot(); + variables.put(name, variable); // TODO: check result + nextSlotNumber += type.type.getSize(); + return variable; + } + + // TODO: make private, thats bogus + public void addMethod(Method method) { + if (methods == null) { + methods = new HashMap<>(); + } + methods.put(new MethodKey(method.name, method.arguments.size()), method); + // TODO: check result + } - @Override - public int getMaxLoopCounter() { - return maxLoopCounter; - } + + int getNextSlot() { + return nextSlotNumber; } public static final class Variable { public final Location location; public final String name; public final Type type; - public final int slot; + int slot = -1; public final boolean readonly; - - public boolean read = false; - - private Variable(Location location, String name, Type type, int slot, boolean readonly) { + + public Variable(Location location, String name, Type type, boolean readonly) { this.location = location; this.name = name; this.type = type; - this.slot = slot; this.readonly = readonly; } - } - - public static final class Constant { - public final Location location; - public final String name; - public final org.objectweb.asm.Type type; - public final Consumer initializer; - - private Constant(Location location, String name, org.objectweb.asm.Type type, Consumer initializer) { - this.location = location; - this.name = name; - this.type = type; - this.initializer = initializer; + + public int getSlot() { + return slot; } } - - public static final class Parameter { + + public static class Parameter { public final Location location; public final String name; public final Type type; @@ -168,197 +300,4 @@ public final class Locals { this.type = type; } } - - private final Reserved reserved; - private final Map methods; - private final Map constants; - private final Type rtnType; - - // TODO: this datastructure runs in linear time for nearly all operations. use linkedhashset instead? - private final Deque scopes = new ArrayDeque<>(); - private final Deque variables = new ArrayDeque<>(); - - public Locals(ExecuteReserved reserved, Map methods) { - this.reserved = reserved; - this.methods = Collections.unmodifiableMap(methods); - this.constants = new HashMap<>(); - this.rtnType = Definition.OBJECT_TYPE; - - incrementScope(); - - // Method variables. - - // This reference. Internal use only. - addVariable(null, Definition.getType("Object"), ExecuteReserved.THIS, true, true); - - // Input map of variables passed to the script. - addVariable(null, Definition.getType("Map"), ExecuteReserved.PARAMS, true, true); - - // Scorer parameter passed to the script. Internal use only. - addVariable(null, Definition.DEF_TYPE, ExecuteReserved.SCORER, true, true); - - // Doc parameter passed to the script. TODO: Currently working as a Map, we can do better? - addVariable(null, Definition.getType("Map"), ExecuteReserved.DOC, true, true); - - // Aggregation _value parameter passed to the script. - addVariable(null, Definition.DEF_TYPE, ExecuteReserved.VALUE, true, true); - - // Shortcut variables. - - // Document's score as a read-only double. - if (reserved.usesScore()) { - addVariable(null, Definition.DOUBLE_TYPE, ExecuteReserved.SCORE, true, true); - } - - // The ctx map set by executable scripts as a read-only map. - if (reserved.usesCtx()) { - addVariable(null, Definition.getType("Map"), ExecuteReserved.CTX, true, true); - } - - // Loop counter to catch infinite loops. Internal use only. - if (reserved.getMaxLoopCounter() > 0) { - addVariable(null, Definition.INT_TYPE, ExecuteReserved.LOOP, true, true); - } - } - - public Locals(FunctionReserved reserved, Locals locals, Type rtnType, List parameters) { - this.reserved = reserved; - this.methods = locals.methods; - this.constants = locals.constants; - this.rtnType = rtnType; - - incrementScope(); - - for (Parameter parameter : parameters) { - addVariable(parameter.location, parameter.type, parameter.name, false, false); - } - - // Loop counter to catch infinite loops. Internal use only. - if (reserved.getMaxLoopCounter() > 0) { - addVariable(null, Definition.INT_TYPE, ExecuteReserved.LOOP, true, true); - } - } - - public int getMaxLoopCounter() { - return reserved.getMaxLoopCounter(); - } - - public Method getMethod(MethodKey key) { - return methods.get(key); - } - - public Type getReturnType() { - return rtnType; - } - - public void incrementScope() { - scopes.push(0); - } - - public void decrementScope() { - int remove = scopes.pop(); - - while (remove > 0) { - Variable variable = variables.pop(); - - // This checks whether or not a variable is used when exiting a local scope. - if (variable.read) { - throw variable.location.createError(new IllegalArgumentException("Variable [" + variable.name + "] is never used.")); - } - - --remove; - } - } - - public Variable getVariable(Location location, String name) { - Iterator itr = variables.iterator(); - - while (itr.hasNext()) { - Variable variable = itr.next(); - - if (variable.name.equals(name)) { - return variable; - } - } - - throw location.createError(new IllegalArgumentException("Variable [" + name + "] is not defined.")); - } - - public boolean isVariable(String name) { - Iterator itr = variables.iterator(); - - while (itr.hasNext()) { - Variable variable = itr.next(); - - if (variable.name.equals(name)) { - return true; - } - } - - return false; - } - - public Variable addVariable(Location location, Type type, String name, boolean readonly, boolean reserved) { - if (!reserved && this.reserved.isReserved(name)) { - throw location.createError(new IllegalArgumentException("Variable [" + name + "] is reserved.")); - } - - if (isVariable(name)) { - throw location.createError(new IllegalArgumentException("Variable [" + name + "] is already defined.")); - } - - Variable previous = variables.peekFirst(); - int slot = 0; - - if (previous != null) { - slot = previous.slot + previous.type.type.getSize(); - } - - Variable variable = new Variable(location, name, type, slot, readonly); - variables.push(variable); - - int update = scopes.pop() + 1; - scopes.push(update); - - return variable; - } - - /** - * Create a new constant. - * - * @param location the location in the script that is creating it - * @param type the type of the constant - * @param name the name of the constant - * @param initializer code to initialize the constant. It will be called when generating the clinit method and is expected to leave the - * value of the constant on the stack. Generating the load instruction is managed by the caller. - * @return the constant - */ - public Constant addConstant(Location location, org.objectweb.asm.Type type, String name, Consumer initializer) { - if (constants.containsKey(name)) { - throw location.createError(new IllegalArgumentException("Constant [" + name + "] is already defined.")); - } - - Constant constant = new Constant(location, name, type, initializer); - constants.put(name, constant); - return constant; - } - - /** - * Create a new constant. - * - * @param location the location in the script that is creating it - * @param type the type of the constant - * @param name the name of the constant - * @param initializer code to initialize the constant. It will be called when generating the clinit method and is expected to leave the - * value of the constant on the stack. Generating the load instruction is managed by the caller. - * @return the constant - */ - public Constant addConstant(Location location, Type type, String name, Consumer initializer) { - return addConstant(location, type.type, name, initializer); - } - - public Collection getConstants() { - return constants.values(); - } } - diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java index f3751892b97..b92bd6733c9 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java @@ -29,11 +29,12 @@ import org.antlr.v4.runtime.Recognizer; import org.antlr.v4.runtime.atn.PredictionMode; import org.antlr.v4.runtime.tree.TerminalNode; import org.elasticsearch.painless.CompilerSettings; -import org.elasticsearch.painless.Locals.ExecuteReserved; -import org.elasticsearch.painless.Locals.FunctionReserved; +import org.elasticsearch.painless.Globals; +import org.elasticsearch.painless.node.SFunction.Reserved; +import org.elasticsearch.painless.node.SSource.MainMethodReserved; +import org.elasticsearch.painless.node.SFunction.FunctionReserved; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Operation; -import org.elasticsearch.painless.Locals.Reserved; import org.elasticsearch.painless.antlr.PainlessParser.AfterthoughtContext; import org.elasticsearch.painless.antlr.PainlessParser.ArgumentContext; import org.elasticsearch.painless.antlr.PainlessParser.ArgumentsContext; @@ -114,6 +115,7 @@ import org.elasticsearch.painless.node.EConditional; import org.elasticsearch.painless.node.EDecimal; import org.elasticsearch.painless.node.EExplicit; import org.elasticsearch.painless.node.EFunctionRef; +import org.elasticsearch.painless.node.ELambda; import org.elasticsearch.painless.node.ENull; import org.elasticsearch.painless.node.ENumeric; import org.elasticsearch.painless.node.EUnary; @@ -151,6 +153,7 @@ import org.objectweb.asm.util.Printer; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; +import java.util.BitSet; import java.util.Deque; import java.util.List; @@ -170,7 +173,7 @@ public final class Walker extends PainlessParserBaseVisitor { private final String sourceText; private final Deque reserved = new ArrayDeque<>(); - private final List synthetic = new ArrayList<>(); + private final Globals globals; private int syntheticCounter = 0; private Walker(String sourceName, String sourceText, CompilerSettings settings, Printer debugStream) { @@ -178,6 +181,7 @@ public final class Walker extends PainlessParserBaseVisitor { this.settings = settings; this.sourceName = Location.computeSourceName(sourceName, sourceText); this.sourceText = sourceText; + this.globals = new Globals(new BitSet(sourceText.length())); this.source = (SSource)visit(buildAntlrTree(sourceText)); } @@ -223,7 +227,7 @@ public final class Walker extends PainlessParserBaseVisitor { @Override public Object visitSource(SourceContext ctx) { - reserved.push(new ExecuteReserved()); + reserved.push(new MainMethodReserved()); List functions = new ArrayList<>(); @@ -236,11 +240,9 @@ public final class Walker extends PainlessParserBaseVisitor { for (StatementContext statement : ctx.statement()) { statements.add((AStatement)visit(statement)); } - - functions.addAll(synthetic); - return new SSource(sourceName, sourceText, debugStream, - (ExecuteReserved)reserved.pop(), location(ctx), functions, statements); + return new SSource(sourceName, sourceText, debugStream, (MainMethodReserved)reserved.pop(), + location(ctx), functions, globals, statements); } @Override @@ -265,7 +267,8 @@ public final class Walker extends PainlessParserBaseVisitor { statements.add((AStatement)visit(statement)); } - return new SFunction((FunctionReserved)reserved.pop(), location(ctx), rtnType, name, paramTypes, paramNames, statements, false); + return new SFunction((FunctionReserved)reserved.pop(), location(ctx), rtnType, name, + paramTypes, paramNames, statements, false); } @Override @@ -977,10 +980,8 @@ public final class Walker extends PainlessParserBaseVisitor { } String name = nextLambda(); - synthetic.add(new SFunction((FunctionReserved)reserved.pop(), location(ctx), "def", name, - paramTypes, paramNames, statements, true)); - return new EFunctionRef(location(ctx), "this", name); - // TODO: use a real node for captures and shit + return new ELambda(name, (FunctionReserved)reserved.pop(), location(ctx), + paramTypes, paramNames, statements); } @Override @@ -1021,8 +1022,8 @@ public final class Walker extends PainlessParserBaseVisitor { new EChain(location, new LVariable(location, "size")))))); String name = nextLambda(); - synthetic.add(new SFunction(new FunctionReserved(), location, arrayType, name, - Arrays.asList("int"), Arrays.asList("size"), Arrays.asList(code), true)); + globals.addSyntheticMethod(new SFunction(new FunctionReserved(), location, arrayType, name, + Arrays.asList("int"), Arrays.asList("size"), Arrays.asList(code), true)); return new EFunctionRef(location(ctx), "this", name); } return new EFunctionRef(location(ctx), ctx.decltype().getText(), ctx.NEW().getText()); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java index fbaaa83a6ad..eb5f73334db 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java @@ -21,6 +21,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition.Cast; import org.elasticsearch.painless.Definition.Type; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.AnalyzerCaster; import org.elasticsearch.painless.Locals; @@ -111,7 +112,7 @@ public abstract class AExpression extends ANode { /** * Writes ASM based on the data collected during the analysis phase. */ - abstract void write(MethodWriter writer); + abstract void write(MethodWriter writer, Globals globals); /** * Inserts {@link ECast} nodes into the tree for implicit casts. Also replaces diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ALink.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ALink.java index 6d52bfe0de1..f8081d0020b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ALink.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ALink.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition.Type; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -91,17 +92,17 @@ public abstract class ALink extends ANode { /** * Write values before a load/store occurs such as an array index. */ - abstract void write(MethodWriter writer); + abstract void write(MethodWriter writer, Globals globals); /** * Write a load for the specific link type. */ - abstract void load(MethodWriter writer); + abstract void load(MethodWriter writer, Globals globals); /** * Write a store for the specific link type. */ - abstract void store(MethodWriter writer); + abstract void store(MethodWriter writer, Globals globals); /** * Used to copy link data from one to another during analysis in the case of replacement. diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStatement.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStatement.java index e34d174ac43..23210472b70 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStatement.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStatement.java @@ -19,7 +19,9 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; +import org.elasticsearch.painless.Locals.Variable; import org.objectweb.asm.Label; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; @@ -88,7 +90,7 @@ public abstract class AStatement extends ANode { * Set to the loop counter variable slot as a shortcut if loop statements * are being counted. */ - int loopCounterSlot = -1; + Variable loopCounter = null; /** * Set to the approximate number of statements in a loop block to prevent @@ -120,5 +122,5 @@ public abstract class AStatement extends ANode { /** * Writes ASM based on the data collected during the analysis phase. */ - abstract void write(MethodWriter writer); + abstract void write(MethodWriter writer, Globals globals); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java index d3b92d7eb08..11b77b0441f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java @@ -21,6 +21,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Location; @@ -604,7 +605,7 @@ public final class EBinary extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (promote.sort == Sort.STRING && operation == Operation.ADD) { @@ -612,13 +613,13 @@ public final class EBinary extends AExpression { writer.writeNewStrings(); } - left.write(writer); + left.write(writer, globals); if (!(left instanceof EBinary) || ((EBinary)left).operation != Operation.ADD || left.actual.sort != Sort.STRING) { writer.writeAppendStrings(left.actual); } - right.write(writer); + right.write(writer, globals); if (!(right instanceof EBinary) || ((EBinary)right).operation != Operation.ADD || right.actual.sort != Sort.STRING) { writer.writeAppendStrings(right.actual); @@ -628,14 +629,14 @@ public final class EBinary extends AExpression { writer.writeToStrings(); } } else if (operation == Operation.FIND) { - writeBuildMatcher(writer); + writeBuildMatcher(writer, globals); writer.invokeVirtual(Definition.MATCHER_TYPE.type, WriterConstants.MATCHER_FIND); } else if (operation == Operation.MATCH) { - writeBuildMatcher(writer); + writeBuildMatcher(writer, globals); writer.invokeVirtual(Definition.MATCHER_TYPE.type, WriterConstants.MATCHER_MATCHES); } else { - left.write(writer); - right.write(writer); + left.write(writer, globals); + right.write(writer, globals); if (promote.sort == Sort.DEF || (shiftDistance != null && shiftDistance.sort == Sort.DEF)) { writer.writeDynamicBinaryInstruction(location, actual, left.actual, right.actual, operation, false); @@ -647,9 +648,9 @@ public final class EBinary extends AExpression { writer.writeBranch(tru, fals); } - private void writeBuildMatcher(MethodWriter writer) { - right.write(writer); - left.write(writer); + private void writeBuildMatcher(MethodWriter writer, Globals globals) { + right.write(writer, globals); + left.write(writer, globals); writer.invokeVirtual(Definition.PATTERN_TYPE.type, WriterConstants.PATTERN_MATCHER); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java index 5aa2daeeb34..9e39ca712f5 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Operation; import org.elasticsearch.painless.Locals; @@ -67,7 +68,7 @@ public final class EBool extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { if (tru != null || fals != null) { if (operation == Operation.AND) { Label localfals = fals == null ? new Label() : fals; @@ -76,8 +77,8 @@ public final class EBool extends AExpression { right.tru = tru; right.fals = fals; - left.write(writer); - right.write(writer); + left.write(writer, globals); + right.write(writer, globals); if (fals == null) { writer.mark(localfals); @@ -89,8 +90,8 @@ public final class EBool extends AExpression { right.tru = tru; right.fals = fals; - left.write(writer); - right.write(writer); + left.write(writer, globals); + right.write(writer, globals); if (tru == null) { writer.mark(localtru); @@ -106,8 +107,8 @@ public final class EBool extends AExpression { left.fals = localfals; right.fals = localfals; - left.write(writer); - right.write(writer); + left.write(writer, globals); + right.write(writer, globals); writer.push(true); writer.goTo(end); @@ -122,8 +123,8 @@ public final class EBool extends AExpression { left.tru = localtru; right.fals = localfals; - left.write(writer); - right.write(writer); + left.write(writer, globals); + right.write(writer, globals); writer.mark(localtru); writer.push(true); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java index 877e79549af..a152422fac4 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -41,7 +42,7 @@ public final class EBoolean extends AExpression { } @Override - void write(MethodWriter adapter) { + void write(MethodWriter adapter, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java index af4e3779b65..333787db962 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java @@ -22,6 +22,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.FunctionRef; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; import org.elasticsearch.painless.Locals; @@ -37,7 +38,7 @@ import java.lang.invoke.LambdaMetafactory; /** * Represents a capturing function reference. */ -public class ECapturingFunctionRef extends AExpression { +public class ECapturingFunctionRef extends AExpression implements ILambda { public final String type; public final String call; @@ -79,21 +80,21 @@ public class ECapturingFunctionRef extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (defPointer != null) { // dynamic interface: push captured parameter on stack // TODO: don't do this: its just to cutover :) writer.push((String)null); - writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.slot); + writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.getSlot()); } else if (ref == null) { // typed interface, dynamic implementation - writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.slot); + writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.getSlot()); String descriptor = Type.getMethodType(expected.type, captured.type.type).getDescriptor(); writer.invokeDynamic(call, descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.REFERENCE, expected.name); } else { // typed interface, typed implementation - writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.slot); + writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.getSlot()); // convert MethodTypes to asm Type for the constant pool. String invokedType = ref.invokedType.toMethodDescriptorString(); Type samMethodType = Type.getMethodType(ref.samMethodType.toMethodDescriptorString()); @@ -119,4 +120,14 @@ public class ECapturingFunctionRef extends AExpression { } } } + + @Override + public String getPointer() { + return defPointer; + } + + @Override + public Type[] getCaptures() { + return new Type[] { captured.type.type }; + } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java index 7892b918ed1..1073125c637 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java @@ -21,6 +21,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition.Cast; import org.elasticsearch.painless.Location; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -50,8 +51,8 @@ final class ECast extends AExpression { } @Override - void write(MethodWriter writer) { - child.write(writer); + void write(MethodWriter writer, Globals globals) { + child.write(writer, globals); writer.writeDebugInfo(location); writer.writeCast(cast); writer.writeBranch(tru, fals); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java index 3be7f068261..b249cf4511e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Cast; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Type; @@ -286,7 +287,7 @@ public final class EChain extends AExpression { * 10. call link{[0]}.store(...) -- store the value on the stack into the 0th index of the array x [...] */ @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); // For the case where the chain represents a String concatenation @@ -306,7 +307,7 @@ public final class EChain extends AExpression { // See individual links for more information on what each of the // write, load, and store methods do. for (ALink link : links) { - link.write(writer); // call the write method on the link to prepare for a load/store operation + link.write(writer, globals); // call the write method on the link to prepare for a load/store operation if (link == last && link.store) { if (cat) { @@ -314,10 +315,10 @@ public final class EChain extends AExpression { // representing a String concatenation. writer.writeDup(link.size, catElementStackSize); // dup the top element and insert it before concat helper on stack - link.load(writer); // read the current link's value + link.load(writer, globals); // read the current link's value writer.writeAppendStrings(link.after); // append the link's value using the StringBuilder - expression.write(writer); // write the bytecode for the rhs expression + expression.write(writer, globals); // write the bytecode for the rhs expression if (!(expression instanceof EBinary) || ((EBinary)expression).operation != Operation.ADD || expression.actual.sort != Sort.STRING) { @@ -331,13 +332,13 @@ public final class EChain extends AExpression { writer.writeDup(link.after.sort.size, link.size); // if this link is also read from dup the value onto the stack } - link.store(writer); // store the link's value from the stack in its respective variable/field/array + link.store(writer, globals); // store the link's value from the stack in its respective variable/field/array } else if (operation != null) { // Handle the case where we are doing a compound assignment that // does not represent a String concatenation. writer.writeDup(link.size, 0); // if necessary, dup the previous link's value to be both loaded from and stored to - link.load(writer); // load the current link's value + link.load(writer, globals); // load the current link's value if (link.load && post) { writer.writeDup(link.after.sort.size, link.size); // dup the value if the link is also @@ -346,7 +347,7 @@ public final class EChain extends AExpression { writer.writeCast(there); // if necessary cast the current link's value // to the promotion type between the lhs and rhs types - expression.write(writer); // write the bytecode for the rhs expression + expression.write(writer, globals); // write the bytecode for the rhs expression // XXX: fix these types, but first we need def compound assignment tests. // its tricky here as there are possibly explicit casts, too. // write the operation instruction for compound assignment @@ -364,22 +365,22 @@ public final class EChain extends AExpression { // read from and is not a post increment } - link.store(writer); // store the link's value from the stack in its respective variable/field/array + link.store(writer, globals); // store the link's value from the stack in its respective variable/field/array } else { // Handle the case for a simple write. - expression.write(writer); // write the bytecode for the rhs expression + expression.write(writer, globals); // write the bytecode for the rhs expression if (link.load) { writer.writeDup(link.after.sort.size, link.size); // dup the value if the link is also read from } - link.store(writer); // store the link's value from the stack in its respective variable/field/array + link.store(writer, globals); // store the link's value from the stack in its respective variable/field/array } } else { // Handle the case for a simple read. - link.load(writer); // read the link's value onto the stack + link.load(writer, globals); // read the link's value onto the stack } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java index 03c6351e95c..53684a19005 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Location; @@ -436,15 +437,15 @@ public final class EComp extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); boolean branch = tru != null || fals != null; - left.write(writer); + left.write(writer, globals); if (!right.isNull) { - right.write(writer); + right.write(writer, globals); } Label jump = tru != null ? tru : fals != null ? fals : new Label(); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java index 024e0c800fc..600626348dd 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.AnalyzerCaster; @@ -78,7 +79,7 @@ public final class EConditional extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); Label localfals = new Label(); @@ -88,11 +89,11 @@ public final class EConditional extends AExpression { left.tru = right.tru = tru; left.fals = right.fals = fals; - condition.write(writer); - left.write(writer); + condition.write(writer, globals); + left.write(writer, globals); writer.goTo(end); writer.mark(localfals); - right.write(writer); + right.write(writer, globals); writer.mark(end); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java index 267d32983b9..b037d25c2d6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; @@ -63,7 +64,7 @@ final class EConstant extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { Sort sort = actual.sort; switch (sort) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java index 0fd7fe46b51..efa453605cb 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -57,7 +58,7 @@ public final class EDecimal extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java index 007a5d59e59..1c186faaeeb 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -54,7 +55,7 @@ public final class EExplicit extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java index 7ab7703d02e..856a876550c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java @@ -21,6 +21,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.FunctionRef; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; import org.elasticsearch.painless.Definition.Method; @@ -35,7 +36,7 @@ import java.lang.invoke.LambdaMetafactory; /** * Represents a function reference. */ -public class EFunctionRef extends AExpression { +public class EFunctionRef extends AExpression implements ILambda { public final String type; public final String call; @@ -83,7 +84,7 @@ public class EFunctionRef extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { if (ref != null) { writer.writeDebugInfo(location); // convert MethodTypes to asm Type for the constant pool. @@ -114,4 +115,14 @@ public class EFunctionRef extends AExpression { writer.push((String)null); } } + + @Override + public String getPointer() { + return defPointer; + } + + @Override + public Type[] getCaptures() { + return new Type[0]; // no captures + } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java index b513e3813c4..d0b531c74d3 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java @@ -20,23 +20,33 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Locals; -import org.elasticsearch.painless.Locals.FunctionReserved; +import org.elasticsearch.painless.Locals.Variable; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; +import org.elasticsearch.painless.node.SFunction.FunctionReserved; +import org.elasticsearch.painless.Globals; +import org.objectweb.asm.Type; +import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class ELambda extends AExpression { +public class ELambda extends AExpression implements ILambda { + final String name; final FunctionReserved reserved; final List paramTypeStrs; final List paramNameStrs; final List statements; + // desugared synthetic method (lambda body) + SFunction desugared; + // method ref (impl detail) + ILambda impl; - public ELambda(FunctionReserved reserved, Location location, - List paramTypes, List paramNames, List statements) { + public ELambda(String name, FunctionReserved reserved, + Location location, List paramTypes, List paramNames, + List statements) { super(location); - + this.name = name; this.reserved = reserved; this.paramTypeStrs = Collections.unmodifiableList(paramTypes); this.paramNameStrs = Collections.unmodifiableList(paramNames); @@ -45,11 +55,40 @@ public class ELambda extends AExpression { @Override void analyze(Locals locals) { - throw createError(new UnsupportedOperationException("Lambda functions are not supported.")); + // desugar lambda body into a synthetic method + desugared = new SFunction(reserved, location, "def", name, + paramTypeStrs, paramNameStrs, statements, true); + desugared.generate(); + List captures = new ArrayList<>(); + desugared.analyze(Locals.newLambdaScope(locals.getProgramScope(), desugared.parameters, captures)); + + // setup reference + EFunctionRef ref = new EFunctionRef(location, "this", name); + ref.expected = expected; + // hack, create a new scope, with our method, so the ref can see it (impl detail) + locals = Locals.newLocalScope(locals); + locals.addMethod(desugared.method); + ref.analyze(locals); + actual = ref.actual; + impl = ref; } @Override - void write(MethodWriter writer) { - throw createError(new IllegalStateException("Illegal tree structure.")); + void write(MethodWriter writer, Globals globals) { + AExpression expr = (AExpression) impl; + expr.write(writer, globals); + // add synthetic method to the queue to be written + globals.addSyntheticMethod(desugared); } + + @Override + public String getPointer() { + return impl.getPointer(); + } + + @Override + public Type[] getCaptures() { + return impl.getCaptures(); + } + } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java index eefc09c5946..0a1242e6507 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Opcodes; @@ -50,7 +51,7 @@ public final class ENull extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.visitInsn(Opcodes.ACONST_NULL); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java index 9abdc8f6a12..e2314880448 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Locals; @@ -96,7 +97,7 @@ public final class ENumeric extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java index f4f73e6101b..f74b91dd5bc 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Type; @@ -177,7 +178,7 @@ public final class EUnary extends AExpression { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (operation == Operation.NOT) { @@ -186,7 +187,7 @@ public final class EUnary extends AExpression { Label end = new Label(); child.fals = localfals; - child.write(writer); + child.write(writer, globals); writer.push(false); writer.goTo(end); @@ -196,11 +197,11 @@ public final class EUnary extends AExpression { } else { child.tru = fals; child.fals = tru; - child.write(writer); + child.write(writer, globals); } } else { Sort sort = promote.sort; - child.write(writer); + child.write(writer, globals); if (operation == Operation.BWNOT) { if (sort == Sort.DEF) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ILambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ILambda.java new file mode 100644 index 00000000000..5a279b3a162 --- /dev/null +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ILambda.java @@ -0,0 +1,40 @@ +/* + * 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.painless.node; + +/** + * Interface for lambda/method reference nodes. They need special handling by LDefCall. + *

+ * This is because they know nothing about the target interface, and can only push + * all their captures onto the stack and defer everything until link-time. + */ +interface ILambda { + + /** Returns reference to resolve at link-time */ + String getPointer(); + + /** Returns the types of captured parameters. Can be empty */ + org.objectweb.asm.Type[] getCaptures(); + + /** Returns the number of captured parameters */ + default int getCaptureCount() { + return getCaptures().length; + } +} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LArrayLength.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LArrayLength.java index 38c1ae43907..1a240747d73 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LArrayLength.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LArrayLength.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -55,18 +56,18 @@ public final class LArrayLength extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); writer.arrayLength(); } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LBrace.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LBrace.java index 91346b7a208..e8c23bf3857 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LBrace.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LBrace.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Locals; @@ -69,18 +70,18 @@ public final class LBrace extends ALink { } @Override - void write(MethodWriter writer) { - index.write(writer); + void write(MethodWriter writer, Globals globals) { + index.write(writer, globals); } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); writer.arrayLoad(after.type); } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); writer.arrayStore(after.type); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java index 1f6e899b1dd..34ad0343aa9 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java @@ -24,6 +24,7 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Struct; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -86,16 +87,16 @@ public final class LCallInvoke extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); for (AExpression argument : arguments) { - argument.write(writer); + argument.write(writer, globals); } if (java.lang.reflect.Modifier.isStatic(method.modifiers)) { @@ -108,7 +109,7 @@ public final class LCallInvoke extends ALink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallLocal.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallLocal.java index 31085171bf6..4503692b48d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallLocal.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallLocal.java @@ -21,6 +21,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.MethodKey; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; @@ -77,23 +78,23 @@ public class LCallLocal extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); for (AExpression argument : arguments) { - argument.write(writer); + argument.write(writer, globals); } writer.invokeStatic(CLASS_TYPE, method.method); } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCast.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCast.java index d2b4f83a823..bf900cedafc 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCast.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCast.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Cast; import org.elasticsearch.painless.AnalyzerCaster; @@ -61,18 +62,18 @@ public final class LCast extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); writer.writeCast(cast); } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java index 5a5333aabe8..02fbb2000f2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Locals; @@ -53,12 +54,12 @@ final class LDefArray extends ALink implements IDefLink { } @Override - void write(MethodWriter writer) { - index.write(writer); + void write(MethodWriter writer, Globals globals) { + index.write(writer, globals); } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); String desc = Type.getMethodDescriptor(after.type, Definition.DEF_TYPE.type, index.actual.type); @@ -66,7 +67,7 @@ final class LDefArray extends ALink implements IDefLink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); String desc = Type.getMethodDescriptor(Definition.VOID_TYPE.type, Definition.DEF_TYPE.type, index.actual.type, after.type); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java index a2c2f150840..716b26d6687 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java @@ -20,10 +20,12 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import org.objectweb.asm.Type; import java.util.ArrayList; import java.util.List; @@ -64,13 +66,11 @@ final class LDefCall extends ALink implements IDefLink { expression.internal = true; expression.analyze(locals); - if (expression instanceof EFunctionRef) { - pointers.add(((EFunctionRef)expression).defPointer); + if (expression instanceof ILambda) { + ILambda lambda = (ILambda) expression; + pointers.add(lambda.getPointer()); recipe |= (1L << (argument + totalCaptures)); // mark argument as deferred reference - } else if (expression instanceof ECapturingFunctionRef) { - pointers.add(((ECapturingFunctionRef)expression).defPointer); - recipe |= (1L << (argument + totalCaptures)); // mark argument as deferred reference - totalCaptures++; + totalCaptures += lambda.getCaptureCount(); } expression.expected = expression.actual; @@ -84,12 +84,12 @@ final class LDefCall extends ALink implements IDefLink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); StringBuilder signature = new StringBuilder(); @@ -100,11 +100,13 @@ final class LDefCall extends ALink implements IDefLink { for (AExpression argument : arguments) { signature.append(argument.actual.type.getDescriptor()); - if (argument instanceof ECapturingFunctionRef) { - ECapturingFunctionRef capturingRef = (ECapturingFunctionRef) argument; - signature.append(capturingRef.captured.type.type.getDescriptor()); + if (argument instanceof ILambda) { + ILambda lambda = (ILambda) argument; + for (Type capture : lambda.getCaptures()) { + signature.append(capture.getDescriptor()); + } } - argument.write(writer); + argument.write(writer, globals); } signature.append(')'); @@ -119,7 +121,7 @@ final class LDefCall extends ALink implements IDefLink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java index 09b48a94f86..125b2bee6fc 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Locals; @@ -50,12 +51,12 @@ final class LDefField extends ALink implements IDefLink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); String desc = Type.getMethodDescriptor(after.type, Definition.DEF_TYPE.type); @@ -63,7 +64,7 @@ final class LDefField extends ALink implements IDefLink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); String desc = Type.getMethodDescriptor(Definition.VOID_TYPE.type, Definition.DEF_TYPE.type, after.type); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LField.java index 049dd2d8524..9fc48c009a2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LField.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Field; import org.elasticsearch.painless.Definition.Sort; @@ -100,12 +101,12 @@ public final class LField extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (java.lang.reflect.Modifier.isStatic(field.modifiers)) { @@ -116,7 +117,7 @@ public final class LField extends ALink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (java.lang.reflect.Modifier.isStatic(field.modifiers)) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LListShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LListShortcut.java index 7b0feb094e1..1cd5620cc17 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LListShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LListShortcut.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; @@ -74,12 +75,12 @@ final class LListShortcut extends ALink { } @Override - void write(MethodWriter writer) { - index.write(writer); + void write(MethodWriter writer, Globals globals) { + index.write(writer, globals); } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (java.lang.reflect.Modifier.isInterface(getter.owner.clazz.getModifiers())) { @@ -94,7 +95,7 @@ final class LListShortcut extends ALink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (java.lang.reflect.Modifier.isInterface(setter.owner.clazz.getModifiers())) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LMapShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LMapShortcut.java index 5d4c5a9e50a..05c2192b870 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LMapShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LMapShortcut.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; @@ -73,12 +74,12 @@ final class LMapShortcut extends ALink { } @Override - void write(MethodWriter writer) { - index.write(writer); + void write(MethodWriter writer, Globals globals) { + index.write(writer, globals); } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (java.lang.reflect.Modifier.isInterface(getter.owner.clazz.getModifiers())) { @@ -93,7 +94,7 @@ final class LMapShortcut extends ALink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (java.lang.reflect.Modifier.isInterface(setter.owner.clazz.getModifiers())) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewArray.java index 15aa01c1d26..312cbf925e1 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewArray.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Locals; @@ -74,16 +75,16 @@ public final class LNewArray extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); for (AExpression argument : arguments) { - argument.write(writer); + argument.write(writer, globals); } if (arguments.size() > 1) { @@ -94,7 +95,7 @@ public final class LNewArray extends ALink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewObj.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewObj.java index aeb6f64f9db..0b28a308e19 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewObj.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewObj.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Struct; @@ -93,12 +94,12 @@ public final class LNewObj extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); writer.newInstance(after.type); @@ -107,14 +108,14 @@ public final class LNewObj extends ALink { } for (AExpression argument : arguments) { - argument.write(writer); + argument.write(writer, globals); } writer.invokeConstructor(constructor.owner.type, constructor.method); } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LRegex.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LRegex.java index 324b6d72cf1..8727f992242 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LRegex.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LRegex.java @@ -19,9 +19,10 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Constant; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; -import org.elasticsearch.painless.Locals.Constant; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -64,25 +65,26 @@ public final class LRegex extends ALink { throw createError(new IllegalArgumentException("Regex constant may only be read [" + pattern + "].")); } - constant = locals.addConstant(location, Definition.PATTERN_TYPE, "regexAt$" + location.getOffset(), this::initializeConstant); + constant = new Constant(location, Definition.PATTERN_TYPE.type, "regexAt$" + location.getOffset(), this::initializeConstant); after = Definition.PATTERN_TYPE; return this; } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); writer.getStatic(WriterConstants.CLASS_TYPE, constant.name, Definition.PATTERN_TYPE.type); + globals.addConstantInitializer(constant); } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LShortcut.java index 73cbc201db4..efaf02bb601 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LShortcut.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; @@ -79,12 +80,12 @@ final class LShortcut extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (java.lang.reflect.Modifier.isInterface(getter.owner.clazz.getModifiers())) { @@ -99,7 +100,7 @@ final class LShortcut extends ALink { } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); if (java.lang.reflect.Modifier.isInterface(setter.owner.clazz.getModifiers())) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LStatic.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LStatic.java index 6f04e9a22c4..3a7c9a35fe5 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LStatic.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LStatic.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; import org.elasticsearch.painless.Locals; @@ -54,17 +55,17 @@ public final class LStatic extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LString.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LString.java index 41eb027e3ab..fac9d413ad7 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LString.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LString.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -51,17 +52,17 @@ public final class LString extends ALink { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { + void load(MethodWriter writer, Globals globals) { writer.push(string); } @Override - void store(MethodWriter writer) { + void store(MethodWriter writer, Globals globals) { throw createError(new IllegalStateException("Illegal tree structure.")); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LVariable.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LVariable.java index 64dc852117d..ad9ba9dfbf6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LVariable.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LVariable.java @@ -21,6 +21,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Locals.Variable; import org.objectweb.asm.Opcodes; @@ -32,7 +33,7 @@ public final class LVariable extends ALink { final String name; - int slot; + Variable variable; public LVariable(Location location, String name) { super(location, 0); @@ -46,30 +47,29 @@ public final class LVariable extends ALink { throw createError(new IllegalArgumentException("Illegal variable [" + name + "] access with target already defined.")); } - Variable variable = locals.getVariable(location, name); + variable = locals.getVariable(location, name); if (store && variable.readonly) { throw createError(new IllegalArgumentException("Variable [" + variable.name + "] is read-only.")); } - slot = variable.slot; after = variable.type; return this; } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { // Do nothing. } @Override - void load(MethodWriter writer) { - writer.visitVarInsn(after.type.getOpcode(Opcodes.ILOAD), slot); + void load(MethodWriter writer, Globals globals) { + writer.visitVarInsn(after.type.getOpcode(Opcodes.ILOAD), variable.getSlot()); } @Override - void store(MethodWriter writer) { - writer.visitVarInsn(after.type.getOpcode(Opcodes.ISTORE), slot); + void store(MethodWriter writer, Globals globals) { + writer.visitVarInsn(after.type.getOpcode(Opcodes.ISTORE), variable.getSlot()); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java index 5fec362ec17..7d459f27504 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; @@ -70,11 +71,11 @@ public final class SBlock extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { for (AStatement statement : statements) { statement.continu = continu; statement.brake = brake; - statement.write(writer); + statement.write(writer, globals); } } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java index d4f8bfff4e4..c791faeadd6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; @@ -45,7 +46,7 @@ public final class SBreak extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.goTo(brake); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java index 42de28e48f5..8632c0eea6d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Locals; @@ -65,7 +66,7 @@ public final class SCatch extends AStatement { throw createError(new ClassCastException("Not an exception type [" + this.type + "].")); } - variable = locals.addVariable(location, type, name, true, false); + variable = locals.addVariable(location, type, name, true); if (block != null) { block.lastSource = lastSource; @@ -84,18 +85,18 @@ public final class SCatch extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label jump = new Label(); writer.mark(jump); - writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.slot); + writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot()); if (block != null) { block.continu = continu; block.brake = brake; - block.write(writer); + block.write(writer, globals); } writer.visitTryCatchBlock(begin, end, jump, variable.type.type.getInternalName()); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java index 802cf90087b..e70f625bb3d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; @@ -48,7 +49,7 @@ public final class SContinue extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.goTo(continu); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java index 5365e72888a..58ff09e45d8 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; @@ -49,9 +50,9 @@ public final class SDeclBlock extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { for (AStatement declaration : declarations) { - declaration.write(writer); + declaration.write(writer, globals); } } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java index a62a287df9c..c19adfd699e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Locals; @@ -62,11 +63,11 @@ public final class SDeclaration extends AStatement { expression = expression.cast(locals); } - variable = locals.addVariable(location, type, name, false, false); + variable = locals.addVariable(location, type, name, false); } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); if (expression == null) { @@ -83,9 +84,9 @@ public final class SDeclaration extends AStatement { default: writer.visitInsn(Opcodes.ACONST_NULL); } } else { - expression.write(writer); + expression.write(writer, globals); } - writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.slot); + writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot()); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java index b25d903dc41..3b94f5799ea 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; @@ -42,7 +43,7 @@ public final class SDo extends AStatement { @Override void analyze(Locals locals) { - locals.incrementScope(); + locals = Locals.newLocalScope(locals); if (block == null) { throw createError(new IllegalArgumentException("Extraneous do while loop.")); @@ -76,15 +77,13 @@ public final class SDo extends AStatement { statementCount = 1; - if (locals.getMaxLoopCounter() > 0) { - loopCounterSlot = locals.getVariable(location, "#loop").slot; + if (locals.hasVariable(Locals.LOOP)) { + loopCounter = locals.getVariable(location, Locals.LOOP); } - - locals.decrementScope(); } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label start = new Label(); @@ -95,14 +94,14 @@ public final class SDo extends AStatement { block.continu = begin; block.brake = end; - block.write(writer); + block.write(writer, globals); writer.mark(begin); condition.fals = end; - condition.write(writer); + condition.write(writer, globals); - writer.writeLoopCounter(loopCounterSlot, Math.max(1, block.statementCount), location); + writer.writeLoopCounter(loopCounter.getSlot(), Math.max(1, block.statementCount), location); writer.goTo(start); writer.mark(end); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java index 48a3f6e3eae..403b377ea9c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java @@ -22,6 +22,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Cast; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.MethodKey; @@ -85,9 +86,9 @@ public class SEach extends AStatement { throw createError(new IllegalArgumentException("Not a type [" + this.type + "].")); } - locals.incrementScope(); + locals = Locals.newLocalScope(locals); - variable = locals.addVariable(location, type, name, true, false); + variable = locals.addVariable(location, type, name, true); if (expression.actual.sort == Sort.ARRAY) { analyzeArray(locals, type); @@ -112,18 +113,16 @@ public class SEach extends AStatement { statementCount = 1; - if (locals.getMaxLoopCounter() > 0) { - loopCounterSlot = locals.getVariable(location, "#loop").slot; + if (locals.hasVariable(Locals.LOOP)) { + loopCounter = locals.getVariable(location, Locals.LOOP); } - - locals.decrementScope(); } void analyzeArray(Locals variables, Type type) { // We must store the array and index as variables for securing slots on the stack, and // also add the location offset to make the names unique in case of nested for each loops. - array = variables.addVariable(location, expression.actual, "#array" + location.getOffset(), true, false); - index = variables.addVariable(location, Definition.INT_TYPE, "#index" + location.getOffset(), true, false); + array = variables.addVariable(location, expression.actual, "#array" + location.getOffset(), true); + index = variables.addVariable(location, Definition.INT_TYPE, "#index" + location.getOffset(), true); indexed = Definition.getType(expression.actual.struct, expression.actual.dimensions - 1); cast = AnalyzerCaster.getLegalCast(location, indexed, type, true, true); } @@ -131,7 +130,7 @@ public class SEach extends AStatement { void analyzeIterable(Locals variables, Type type) { // We must store the iterator as a variable for securing a slot on the stack, and // also add the location offset to make the name unique in case of nested for each loops. - iterator = variables.addVariable(location, Definition.getType("Iterator"), "#itr" + location.getOffset(), true, false); + iterator = variables.addVariable(location, Definition.getType("Iterator"), "#itr" + location.getOffset(), true); if (expression.actual.sort == Sort.DEF) { method = null; @@ -148,49 +147,49 @@ public class SEach extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); if (array != null) { - writeArray(writer); + writeArray(writer, globals); } else if (iterator != null) { - writeIterable(writer); + writeIterable(writer, globals); } else { throw createError(new IllegalStateException("Illegal tree structure.")); } } - void writeArray(MethodWriter writer) { - expression.write(writer); - writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ISTORE), array.slot); + void writeArray(MethodWriter writer, Globals globals) { + expression.write(writer, globals); + writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ISTORE), array.getSlot()); writer.push(-1); - writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ISTORE), index.slot); + writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ISTORE), index.getSlot()); Label begin = new Label(); Label end = new Label(); writer.mark(begin); - writer.visitIincInsn(index.slot, 1); - writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ILOAD), index.slot); - writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ILOAD), array.slot); + writer.visitIincInsn(index.getSlot(), 1); + writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ILOAD), index.getSlot()); + writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ILOAD), array.getSlot()); writer.arrayLength(); writer.ifICmp(MethodWriter.GE, end); - writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ILOAD), array.slot); - writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ILOAD), index.slot); + writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ILOAD), array.getSlot()); + writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ILOAD), index.getSlot()); writer.arrayLoad(indexed.type); writer.writeCast(cast); - writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.slot); + writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot()); - block.write(writer); + block.write(writer, globals); writer.goTo(begin); writer.mark(end); } - void writeIterable(MethodWriter writer) { - expression.write(writer); + void writeIterable(MethodWriter writer, Globals globals) { + expression.write(writer, globals); if (method == null) { Type itr = Definition.getType("Iterator"); @@ -202,23 +201,23 @@ public class SEach extends AStatement { writer.invokeVirtual(method.owner.type, method.method); } - writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ISTORE), iterator.slot); + writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ISTORE), iterator.getSlot()); Label begin = new Label(); Label end = new Label(); writer.mark(begin); - writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ILOAD), iterator.slot); + writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ILOAD), iterator.getSlot()); writer.invokeInterface(ITERATOR_TYPE, ITERATOR_HASNEXT); writer.ifZCmp(MethodWriter.EQ, end); - writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ILOAD), iterator.slot); + writer.visitVarInsn(iterator.type.type.getOpcode(Opcodes.ILOAD), iterator.getSlot()); writer.invokeInterface(ITERATOR_TYPE, ITERATOR_NEXT); writer.writeCast(cast); - writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.slot); + writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot()); - block.write(writer); + block.write(writer, globals); writer.goTo(begin); writer.mark(end); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java index 8817db95be6..c6cf0a47c8f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java @@ -22,6 +22,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Sort; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -63,9 +64,9 @@ public final class SExpression extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); - expression.write(writer); + expression.write(writer, globals); if (methodEscape) { writer.returnValue(); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java index cc9dee20138..b2cf1da2594 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; @@ -46,7 +47,7 @@ public final class SFor extends AStatement { @Override void analyze(Locals locals) { - locals.incrementScope(); + locals = Locals.newLocalScope(locals); boolean continuous = false; @@ -116,15 +117,13 @@ public final class SFor extends AStatement { statementCount = 1; - if (locals.getMaxLoopCounter() > 0) { - loopCounterSlot = locals.getVariable(location, "#loop").slot; + if (locals.hasVariable(Locals.LOOP)) { + loopCounter = locals.getVariable(location, Locals.LOOP); } - - locals.decrementScope(); } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label start = new Label(); @@ -132,11 +131,11 @@ public final class SFor extends AStatement { Label end = new Label(); if (initializer instanceof SDeclBlock) { - ((SDeclBlock)initializer).write(writer); + ((SDeclBlock)initializer).write(writer, globals); } else if (initializer instanceof AExpression) { AExpression initializer = (AExpression)this.initializer; - initializer.write(writer); + initializer.write(writer, globals); writer.writePop(initializer.expected.sort.size); } @@ -144,7 +143,7 @@ public final class SFor extends AStatement { if (condition != null) { condition.fals = end; - condition.write(writer); + condition.write(writer, globals); } boolean allEscape = false; @@ -158,15 +157,15 @@ public final class SFor extends AStatement { ++statementCount; } - writer.writeLoopCounter(loopCounterSlot, statementCount, location); - block.write(writer); + writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location); + block.write(writer, globals); } else { - writer.writeLoopCounter(loopCounterSlot, 1, location); + writer.writeLoopCounter(loopCounter.getSlot(), 1, location); } if (afterthought != null) { writer.mark(begin); - afterthought.write(writer); + afterthought.write(writer, globals); } if (afterthought != null || !allEscape) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java index 60015844a96..8d3db7f811a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java @@ -19,27 +19,26 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Constant; import org.elasticsearch.painless.Def; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Locals.Parameter; -import org.elasticsearch.painless.Locals.FunctionReserved; import org.elasticsearch.painless.Locals.Variable; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; import org.elasticsearch.painless.WriterConstants; import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Handle; import org.objectweb.asm.Opcodes; import java.lang.invoke.MethodType; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.BitSet; import java.util.Collections; import java.util.List; @@ -51,17 +50,17 @@ import static org.elasticsearch.painless.WriterConstants.CLASS_TYPE; public class SFunction extends AStatement { final FunctionReserved reserved; final String rtnTypeStr; - final String name; + public final String name; final List paramTypeStrs; final List paramNameStrs; final List statements; - final boolean synthetic; + public final boolean synthetic; Type rtnType = null; List parameters = new ArrayList<>(); Method method = null; - Locals locals = null; + Variable loop = null; public SFunction(FunctionReserved reserved, Location location, String rtnType, String name, List paramTypes, @@ -115,10 +114,7 @@ public class SFunction extends AStatement { throw createError(new IllegalArgumentException("Cannot generate an empty function [" + name + "].")); } - this.locals = new Locals(reserved, locals, rtnType, parameters); - locals = this.locals; - - locals.incrementScope(); + locals = Locals.newLocalScope(locals); AStatement last = statements.get(statements.size() - 1); @@ -141,37 +137,33 @@ public class SFunction extends AStatement { throw createError(new IllegalArgumentException("Not all paths provide a return value for method [" + name + "].")); } - locals.decrementScope(); - - String staticHandleFieldName = Def.getUserFunctionHandleFieldName(name, parameters.size()); - locals.addConstant(location, WriterConstants.METHOD_HANDLE_TYPE, staticHandleFieldName, this::initializeConstant); + if (reserved.getMaxLoopCounter() > 0) { + loop = locals.getVariable(null, FunctionReserved.LOOP); + } } /** Writes the function to given ClassVisitor. */ - void write (ClassVisitor writer, BitSet statements) { + void write (ClassVisitor writer, Globals globals) { int access = Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC; if (synthetic) { access |= Opcodes.ACC_SYNTHETIC; } - final MethodWriter function = new MethodWriter(access, method.method, writer, statements); - write(function); + final MethodWriter function = new MethodWriter(access, method.method, writer, globals.getStatements()); + write(function, globals); function.endMethod(); } @Override - void write(MethodWriter function) { + void write(MethodWriter function, Globals globals) { if (reserved.getMaxLoopCounter() > 0) { // if there is infinite loop protection, we do this once: // int #loop = settings.getMaxLoopCounter() - - Variable loop = locals.getVariable(null, FunctionReserved.LOOP); - function.push(reserved.getMaxLoopCounter()); - function.visitVarInsn(Opcodes.ISTORE, loop.slot); + function.visitVarInsn(Opcodes.ISTORE, loop.getSlot()); } for (AStatement statement : statements) { - statement.write(function); + statement.write(function, globals); } if (!methodEscape) { @@ -181,6 +173,10 @@ public class SFunction extends AStatement { throw createError(new IllegalStateException("Illegal tree structure.")); } } + + String staticHandleFieldName = Def.getUserFunctionHandleFieldName(name, parameters.size()); + globals.addConstantInitializer(new Constant(location, WriterConstants.METHOD_HANDLE_TYPE, + staticHandleFieldName, this::initializeConstant)); } private void initializeConstant(MethodWriter writer) { @@ -191,4 +187,43 @@ public class SFunction extends AStatement { false); writer.push(handle); } + + /** + * Tracks reserved variables. Must be given to any source of input + * prior to beginning the analysis phase so that reserved variables + * are known ahead of time to assign appropriate slots without + * being wasteful. + */ + public interface Reserved { + void markReserved(String name); + boolean isReserved(String name); + + void setMaxLoopCounter(int max); + int getMaxLoopCounter(); + } + + public static final class FunctionReserved implements Reserved { + public static final String THIS = "#this"; + public static final String LOOP = "#loop"; + + private int maxLoopCounter = 0; + + public void markReserved(String name) { + // Do nothing. + } + + public boolean isReserved(String name) { + return name.equals(THIS) || name.equals(LOOP); + } + + @Override + public void setMaxLoopCounter(int max) { + maxLoopCounter = max; + } + + @Override + public int getMaxLoopCounter() { + return maxLoopCounter; + } + } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java index a46075af9a1..1b0c0ffb348 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; @@ -58,9 +59,7 @@ public final class SIf extends AStatement { ifblock.inLoop = inLoop; ifblock.lastLoop = lastLoop; - locals.incrementScope(); - ifblock.analyze(locals); - locals.decrementScope(); + ifblock.analyze(Locals.newLocalScope(locals)); anyContinue = ifblock.anyContinue; anyBreak = ifblock.anyBreak; @@ -68,17 +67,17 @@ public final class SIf extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label fals = new Label(); condition.fals = fals; - condition.write(writer); + condition.write(writer, globals); ifblock.continu = continu; ifblock.brake = brake; - ifblock.write(writer); + ifblock.write(writer, globals); writer.mark(fals); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java index 22cbfe25614..612969acfff 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; @@ -60,9 +61,7 @@ public final class SIfElse extends AStatement { ifblock.inLoop = inLoop; ifblock.lastLoop = lastLoop; - locals.incrementScope(); - ifblock.analyze(locals); - locals.decrementScope(); + ifblock.analyze(Locals.newLocalScope(locals)); anyContinue = ifblock.anyContinue; anyBreak = ifblock.anyBreak; @@ -76,9 +75,7 @@ public final class SIfElse extends AStatement { elseblock.inLoop = inLoop; elseblock.lastLoop = lastLoop; - locals.incrementScope(); - elseblock.analyze(locals); - locals.decrementScope(); + elseblock.analyze(Locals.newLocalScope(locals)); methodEscape = ifblock.methodEscape && elseblock.methodEscape; loopEscape = ifblock.loopEscape && elseblock.loopEscape; @@ -89,18 +86,18 @@ public final class SIfElse extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label end = new Label(); Label fals = elseblock != null ? new Label() : end; condition.fals = fals; - condition.write(writer); + condition.write(writer, globals); ifblock.continu = continu; ifblock.brake = brake; - ifblock.write(writer); + ifblock.write(writer, globals); if (!ifblock.allEscape) { writer.goTo(end); @@ -110,7 +107,7 @@ public final class SIfElse extends AStatement { elseblock.continu = continu; elseblock.brake = brake; - elseblock.write(writer); + elseblock.write(writer, globals); writer.mark(end); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java index e789f3372e3..2c46b3ecfaf 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Location; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -51,9 +52,9 @@ public final class SReturn extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); - expression.write(writer); + expression.write(writer, globals); writer.returnValue(); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java index 1d3bb74bc31..5e932072ce1 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java @@ -19,13 +19,14 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Constant; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.MethodKey; import org.elasticsearch.painless.Executable; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; -import org.elasticsearch.painless.Locals.Constant; -import org.elasticsearch.painless.Locals.ExecuteReserved; import org.elasticsearch.painless.Locals.Variable; +import org.elasticsearch.painless.node.SFunction.Reserved; import org.elasticsearch.painless.WriterConstants; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; @@ -35,7 +36,9 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.util.Printer; import org.objectweb.asm.util.TraceClassVisitor; +import java.util.ArrayList; import java.util.BitSet; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -56,24 +59,28 @@ public final class SSource extends AStatement { final String name; final String source; final Printer debugStream; - final ExecuteReserved reserved; + final MainMethodReserved reserved; final List functions; + final Globals globals; final List statements; - private Locals locals; - private BitSet expressions; + private Locals mainMethod; private byte[] bytes; - public SSource(String name, String source, Printer debugStream, ExecuteReserved reserved, Location location, - List functions, List statements) { + public SSource(String name, String source, Printer debugStream, MainMethodReserved reserved, Location location, + List functions, Globals globals, List statements) { super(location); this.name = name; this.source = source; this.debugStream = debugStream; this.reserved = reserved; + // process any synthetic functions generated by walker (because right now, thats still easy) + functions.addAll(globals.getSyntheticMethods().values()); + globals.getSyntheticMethods().clear(); this.functions = Collections.unmodifiableList(functions); this.statements = Collections.unmodifiableList(statements); + this.globals = globals; } public void analyze() { @@ -89,21 +96,22 @@ public final class SSource extends AStatement { } } - locals = new Locals(reserved, methods); - analyze(locals); + analyze(Locals.newProgramScope(methods.values())); } @Override - void analyze(Locals locals) { + void analyze(Locals program) { for (SFunction function : functions) { - function.analyze(locals); + Locals functionLocals = Locals.newFunctionScope(program, function.rtnType, function.parameters, + function.reserved.getMaxLoopCounter()); + function.analyze(functionLocals); } if (statements == null || statements.isEmpty()) { throw createError(new IllegalArgumentException("Cannot generate an empty script.")); } - locals.incrementScope(); + mainMethod = Locals.newMainMethodScope(program, reserved.usesScore(), reserved.usesCtx(), reserved.getMaxLoopCounter()); AStatement last = statements.get(statements.size() - 1); @@ -116,13 +124,11 @@ public final class SSource extends AStatement { statement.lastSource = statement == last; - statement.analyze(locals); + statement.analyze(mainMethod); methodEscape = statement.methodEscape; allEscape = statement.allEscape; } - - locals.decrementScope(); } public void write() { @@ -144,10 +150,8 @@ public final class SSource extends AStatement { visitor.visit(classVersion, classAccess, className, null, classBase, classInterfaces); visitor.visitSource(Location.computeSourceName(name, source), null); - expressions = new BitSet(source.length()); - // Write the constructor: - MethodWriter constructor = new MethodWriter(Opcodes.ACC_PUBLIC, CONSTRUCTOR, visitor, expressions); + MethodWriter constructor = new MethodWriter(Opcodes.ACC_PUBLIC, CONSTRUCTOR, visitor, globals.getStatements()); constructor.visitCode(); constructor.loadThis(); constructor.loadArgs(); @@ -156,20 +160,31 @@ public final class SSource extends AStatement { constructor.endMethod(); // Write the execute method: - MethodWriter execute = new MethodWriter(Opcodes.ACC_PUBLIC, EXECUTE, visitor, expressions); + MethodWriter execute = new MethodWriter(Opcodes.ACC_PUBLIC, EXECUTE, visitor, globals.getStatements()); execute.visitCode(); - write(execute); + write(execute, globals); execute.endMethod(); // Write all functions: for (SFunction function : functions) { - function.write(visitor, expressions); + function.write(visitor, globals); + } + + // Write all synthetic functions. Note that this process may add more :) + while (!globals.getSyntheticMethods().isEmpty()) { + List current = new ArrayList<>(globals.getSyntheticMethods().values()); + globals.getSyntheticMethods().clear(); + for (SFunction function : current) { + function.write(visitor, globals); + } } // Write the constants - if (false == locals.getConstants().isEmpty()) { + if (false == globals.getConstantInitializers().isEmpty()) { + Collection inits = globals.getConstantInitializers().values(); + // Fields - for (Constant constant : locals.getConstants()) { + for (Constant constant : inits) { visitor.visitField( Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, constant.name, @@ -180,8 +195,8 @@ public final class SSource extends AStatement { // Initialize the constants in a static initializer final MethodWriter clinit = new MethodWriter(Opcodes.ACC_STATIC, - WriterConstants.CLINIT, visitor, expressions); - for (Constant constant : locals.getConstants()) { + WriterConstants.CLINIT, visitor, globals.getStatements()); + for (Constant constant : inits) { constant.initializer.accept(clinit); clinit.putStatic(CLASS_TYPE, constant.name, constant.type); } @@ -196,44 +211,44 @@ public final class SSource extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { if (reserved.usesScore()) { // if the _score value is used, we do this once: // final double _score = scorer.score(); - Variable scorer = locals.getVariable(null, ExecuteReserved.SCORER); - Variable score = locals.getVariable(null, ExecuteReserved.SCORE); + Variable scorer = mainMethod.getVariable(null, Locals.SCORER); + Variable score = mainMethod.getVariable(null, Locals.SCORE); - writer.visitVarInsn(Opcodes.ALOAD, scorer.slot); + writer.visitVarInsn(Opcodes.ALOAD, scorer.getSlot()); writer.invokeVirtual(WriterConstants.SCORER_TYPE, WriterConstants.SCORER_SCORE); writer.visitInsn(Opcodes.F2D); - writer.visitVarInsn(Opcodes.DSTORE, score.slot); + writer.visitVarInsn(Opcodes.DSTORE, score.getSlot()); } if (reserved.usesCtx()) { // if the _ctx value is used, we do this once: // final Map ctx = input.get("ctx"); - Variable input = locals.getVariable(null, ExecuteReserved.PARAMS); - Variable ctx = locals.getVariable(null, ExecuteReserved.CTX); + Variable input = mainMethod.getVariable(null, Locals.PARAMS); + Variable ctx = mainMethod.getVariable(null, Locals.CTX); - writer.visitVarInsn(Opcodes.ALOAD, input.slot); - writer.push(ExecuteReserved.CTX); + writer.visitVarInsn(Opcodes.ALOAD, input.getSlot()); + writer.push(Locals.CTX); writer.invokeInterface(MAP_TYPE, MAP_GET); - writer.visitVarInsn(Opcodes.ASTORE, ctx.slot); + writer.visitVarInsn(Opcodes.ASTORE, ctx.getSlot()); } if (reserved.getMaxLoopCounter() > 0) { // if there is infinite loop protection, we do this once: // int #loop = settings.getMaxLoopCounter() - Variable loop = locals.getVariable(null, ExecuteReserved.LOOP); + Variable loop = mainMethod.getVariable(null, Locals.LOOP); writer.push(reserved.getMaxLoopCounter()); - writer.visitVarInsn(Opcodes.ISTORE, loop.slot); + writer.visitVarInsn(Opcodes.ISTORE, loop.getSlot()); } for (AStatement statement : statements) { - statement.write(writer); + statement.write(writer, globals); } if (!methodEscape) { @@ -242,11 +257,50 @@ public final class SSource extends AStatement { } } - public BitSet getExpressions() { - return expressions; + public BitSet getStatements() { + return globals.getStatements(); } public byte[] getBytes() { return bytes; } + + + public static final class MainMethodReserved implements Reserved { + private boolean score = false; + private boolean ctx = false; + private int maxLoopCounter = 0; + + @Override + public void markReserved(String name) { + if (Locals.SCORE.equals(name)) { + score = true; + } else if (Locals.CTX.equals(name)) { + ctx = true; + } + } + + @Override + public boolean isReserved(String name) { + return Locals.KEYWORDS.contains(name); + } + + public boolean usesScore() { + return score; + } + + public boolean usesCtx() { + return ctx; + } + + @Override + public void setMaxLoopCounter(int max) { + maxLoopCounter = max; + } + + @Override + public int getMaxLoopCounter() { + return maxLoopCounter; + } + } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java index db04d622839..ffa1b89dfe2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -50,9 +51,9 @@ public final class SThrow extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); - expression.write(writer); + expression.write(writer, globals); writer.throwException(); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java index 42fffc759ce..0295d32ae35 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; import org.elasticsearch.painless.Location; @@ -52,9 +53,7 @@ public final class STry extends AStatement { block.inLoop = inLoop; block.lastLoop = lastLoop; - locals.incrementScope(); - block.analyze(locals); - locals.decrementScope(); + block.analyze(Locals.newLocalScope(locals)); methodEscape = block.methodEscape; loopEscape = block.loopEscape; @@ -69,9 +68,7 @@ public final class STry extends AStatement { catc.inLoop = inLoop; catc.lastLoop = lastLoop; - locals.incrementScope(); - catc.analyze(locals); - locals.decrementScope(); + catc.analyze(Locals.newLocalScope(locals)); methodEscape &= catc.methodEscape; loopEscape &= catc.loopEscape; @@ -86,7 +83,7 @@ public final class STry extends AStatement { } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label begin = new Label(); @@ -97,7 +94,7 @@ public final class STry extends AStatement { block.continu = continu; block.brake = brake; - block.write(writer); + block.write(writer, globals); if (!block.allEscape) { writer.goTo(exception); @@ -109,7 +106,7 @@ public final class STry extends AStatement { catc.begin = begin; catc.end = end; catc.exception = catches.size() > 1 ? exception : null; - catc.write(writer); + catc.write(writer, globals); } if (!block.allEscape || catches.size() > 1) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java index 20478a55aa0..39b48781b46 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; @@ -42,7 +43,7 @@ public final class SWhile extends AStatement { @Override void analyze(Locals locals) { - locals.incrementScope(); + locals = Locals.newLocalScope(locals); condition.expected = Definition.BOOLEAN_TYPE; condition.analyze(locals); @@ -82,15 +83,13 @@ public final class SWhile extends AStatement { statementCount = 1; - if (locals.getMaxLoopCounter() > 0) { - loopCounterSlot = locals.getVariable(location, "#loop").slot; + if (locals.hasVariable(Locals.LOOP)) { + loopCounter = locals.getVariable(location, Locals.LOOP); } - - locals.decrementScope(); } @Override - void write(MethodWriter writer) { + void write(MethodWriter writer, Globals globals) { writer.writeStatementOffset(location); Label begin = new Label(); @@ -99,16 +98,16 @@ public final class SWhile extends AStatement { writer.mark(begin); condition.fals = end; - condition.write(writer); + condition.write(writer, globals); if (block != null) { - writer.writeLoopCounter(loopCounterSlot, Math.max(1, block.statementCount), location); + writer.writeLoopCounter(loopCounter.getSlot(), Math.max(1, block.statementCount), location); block.continu = begin; block.brake = end; - block.write(writer); + block.write(writer, globals); } else { - writer.writeLoopCounter(loopCounterSlot, 1, location); + writer.writeLoopCounter(loopCounter.getSlot(), 1, location); } if (block == null || !block.allEscape) { diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ReservedWordTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ReservedWordTests.java index e1dbe9db0f7..fdc4fba4313 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ReservedWordTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ReservedWordTests.java @@ -30,7 +30,7 @@ public class ReservedWordTests extends ScriptTestCase { IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("int _score = 5; return _score;"); }); - assertTrue(expected.getMessage().contains("Variable [_score] is reserved")); + assertTrue(expected.getMessage().contains("Variable [_score] is already defined")); } /** check that we can't write to _score, its read-only! */ @@ -46,7 +46,7 @@ public class ReservedWordTests extends ScriptTestCase { IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("int doc = 5; return doc;"); }); - assertTrue(expected.getMessage().contains("Variable [doc] is reserved")); + assertTrue(expected.getMessage().contains("Variable [doc] is already defined")); } /** check that we can't write to doc, its read-only! */ @@ -62,7 +62,7 @@ public class ReservedWordTests extends ScriptTestCase { IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("int ctx = 5; return ctx;"); }); - assertTrue(expected.getMessage().contains("Variable [ctx] is reserved")); + assertTrue(expected.getMessage().contains("Variable [ctx] is already defined")); } /** check that we can't write to ctx, its read-only! */ @@ -83,7 +83,7 @@ public class ReservedWordTests extends ScriptTestCase { IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("int _value = 5; return _value;"); }); - assertTrue(expected.getMessage().contains("Variable [_value] is reserved")); + assertTrue(expected.getMessage().contains("Variable [_value] is already defined")); } /** check that we can't write to _value, its read-only! */ From 420dc721243f7c2ae1920349885a4fd6d7a808a7 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sat, 18 Jun 2016 08:39:10 +0200 Subject: [PATCH 42/87] Add ClusterName#value as the default instead of it's toString method --- .../node/internal/InternalSettingsPreparer.java | 2 +- .../node/internal/InternalSettingsPreparerTests.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java index 7a1c6321c43..3ee704c42aa 100644 --- a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java +++ b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java @@ -163,7 +163,7 @@ public class InternalSettingsPreparer { // put the cluster name if (output.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) == null) { - output.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)); + output.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY).value()); } replacePromptPlaceholders(output, terminal); diff --git a/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java index 226f6eae958..5637e937c1f 100644 --- a/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java +++ b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java @@ -68,6 +68,13 @@ public class InternalSettingsPreparerTests extends ESTestCase { assertTrue(configDir, configDir.startsWith(home)); } + public void testDefaultClusterName() { + Settings settings = InternalSettingsPreparer.prepareSettings(Settings.EMPTY); + assertEquals("elasticsearch", settings.get("cluster.name")); + settings = InternalSettingsPreparer.prepareSettings(Settings.builder().put("cluster.name", "foobar").build()); + assertEquals("foobar", settings.get("cluster.name")); + } + public void testReplacePromptPlaceholders() { MockTerminal terminal = new MockTerminal(); terminal.addTextInput("text"); From 5c98818f480b2ab5f066def5e0f9366af90e68e0 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sat, 18 Jun 2016 10:54:12 +0200 Subject: [PATCH 43/87] fix compilation --- .../java/org/elasticsearch/messy/tests/SearchFieldsTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java index ba258490119..d834f0fcf6d 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.messy.tests; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.common.Priority; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -373,7 +374,7 @@ public class SearchFieldsTests extends ESIntegTestCase { public void testScriptFieldsForNullReturn() throws Exception { client().prepareIndex("test", "type1", "1") .setSource("foo", "bar") - .setRefresh(true).get(); + .setRefreshPolicy("true").get(); SearchResponse response = client().prepareSearch().setQuery(matchAllQuery()) .addScriptField("test_script_1", new Script("return null")) From a14ba1e5b24280460b9c9163e105219514562d2a Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 18 Jun 2016 10:23:35 -0400 Subject: [PATCH 44/87] Painless: add lambda captures --- .../elasticsearch/painless/LambdaLocals.java | 62 -------- .../org/elasticsearch/painless/Locals.java | 61 +++++--- .../elasticsearch/painless/node/ANode.java | 13 +- .../elasticsearch/painless/node/EBinary.java | 16 +- .../elasticsearch/painless/node/EBool.java | 16 +- .../elasticsearch/painless/node/EBoolean.java | 5 + .../painless/node/ECapturingFunctionRef.java | 19 ++- .../elasticsearch/painless/node/ECast.java | 14 +- .../elasticsearch/painless/node/EChain.java | 14 +- .../elasticsearch/painless/node/EComp.java | 16 +- .../painless/node/EConditional.java | 17 ++- .../painless/node/EConstant.java | 6 + .../elasticsearch/painless/node/EDecimal.java | 10 +- .../painless/node/EExplicit.java | 12 +- .../painless/node/EFunctionRef.java | 9 +- .../elasticsearch/painless/node/ELambda.java | 141 +++++++++++++++--- .../elasticsearch/painless/node/ENull.java | 6 + .../elasticsearch/painless/node/ENumeric.java | 9 +- .../elasticsearch/painless/node/EUnary.java | 13 +- .../painless/node/LArrayLength.java | 8 +- .../elasticsearch/painless/node/LBrace.java | 9 +- .../painless/node/LCallInvoke.java | 15 +- .../painless/node/LCallLocal.java | 13 +- .../elasticsearch/painless/node/LCast.java | 6 + .../painless/node/LDefArray.java | 11 +- .../elasticsearch/painless/node/LDefCall.java | 13 +- .../painless/node/LDefField.java | 8 +- .../elasticsearch/painless/node/LField.java | 7 +- .../painless/node/LListShortcut.java | 11 +- .../painless/node/LMapShortcut.java | 11 +- .../painless/node/LNewArray.java | 13 +- .../elasticsearch/painless/node/LNewObj.java | 13 +- .../elasticsearch/painless/node/LRegex.java | 4 + .../painless/node/LShortcut.java | 9 +- .../elasticsearch/painless/node/LStatic.java | 9 +- .../elasticsearch/painless/node/LString.java | 8 +- .../painless/node/LVariable.java | 10 +- .../elasticsearch/painless/node/SBlock.java | 8 + .../elasticsearch/painless/node/SBreak.java | 5 + .../elasticsearch/painless/node/SCatch.java | 16 +- .../painless/node/SContinue.java | 5 + .../painless/node/SDeclBlock.java | 8 + .../painless/node/SDeclaration.java | 16 +- .../org/elasticsearch/painless/node/SDo.java | 14 +- .../elasticsearch/painless/node/SEach.java | 18 ++- .../painless/node/SExpression.java | 11 +- .../org/elasticsearch/painless/node/SFor.java | 19 +++ .../painless/node/SFunction.java | 18 ++- .../org/elasticsearch/painless/node/SIf.java | 14 +- .../elasticsearch/painless/node/SIfElse.java | 17 ++- .../elasticsearch/painless/node/SReturn.java | 10 +- .../elasticsearch/painless/node/SSource.java | 18 ++- .../elasticsearch/painless/node/SThrow.java | 10 +- .../org/elasticsearch/painless/node/STry.java | 11 ++ .../elasticsearch/painless/node/SWhile.java | 14 +- .../elasticsearch/painless/LambdaTests.java | 30 ++++ 56 files changed, 718 insertions(+), 181 deletions(-) delete mode 100644 modules/lang-painless/src/main/java/org/elasticsearch/painless/LambdaLocals.java diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/LambdaLocals.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/LambdaLocals.java deleted file mode 100644 index 9c01bc4c628..00000000000 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/LambdaLocals.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.painless; - -import org.elasticsearch.painless.Definition.Type; - -import java.util.List; -import java.util.Objects; - -/** Extension of locals for lambdas */ -// Note: this isn't functional yet, it throws UOE -// TODO: implement slot renumbering for captures. -class LambdaLocals extends Locals { - private List captures; - - LambdaLocals(Locals parent, List parameters, List captures) { - super(parent); - for (Parameter parameter : parameters) { - defineVariable(parameter.location, parameter.type, parameter.name, false); - } - this.captures = Objects.requireNonNull(captures); - } - - @Override - public Variable getVariable(Location location, String name) { - Variable variable = lookupVariable(location, name); - if (variable != null) { - return variable; - } - if (getParent() != null) { - variable = getParent().getVariable(location, name); - if (variable != null) { - assert captures != null; // unused right now - // make it read-only, and record that it was used. - throw new UnsupportedOperationException("lambda capture is not supported"); - } - } - throw location.createError(new IllegalArgumentException("Variable [" + name + "] is not defined.")); - } - - @Override - public Type getReturnType() { - return Definition.DEF_TYPE; - } -} diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java index 8cb99ed2404..0893a51bc47 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java @@ -35,7 +35,7 @@ import java.util.Set; /** * Tracks user defined methods and variables across compilation phases. */ -public class Locals { +public final class Locals { /** Reserved word: params map parameter */ public static final String PARAMS = "params"; @@ -64,9 +64,23 @@ public class Locals { return new Locals(currentScope); } - /** Creates a new lambda scope inside the current scope */ - public static Locals newLambdaScope(Locals currentScope, List parameters, List captures) { - return new LambdaLocals(currentScope, parameters, captures); + /** + * Creates a new lambda scope inside the current scope + *

+ * This is just like {@link #newFunctionScope}, except the captured parameters are made read-only. + */ + public static Locals newLambdaScope(Locals programScope, List parameters, int captureCount, int maxLoopCounter) { + Locals locals = new Locals(programScope, Definition.DEF_TYPE); + for (int i = 0; i < parameters.size(); i++) { + Parameter parameter = parameters.get(i); + boolean isCapture = i < captureCount; + locals.defineVariable(parameter.location, parameter.type, parameter.name, isCapture); + } + // Loop counter to catch infinite loops. Internal use only. + if (maxLoopCounter > 0) { + locals.defineVariable(null, Definition.INT_TYPE, LOOP, true); + } + return locals; } /** Creates a new function scope inside the current scope */ @@ -129,7 +143,7 @@ public class Locals { } /** Checks if a variable exists or not, in this scope or any parents. */ - public final boolean hasVariable(String name) { + public boolean hasVariable(String name) { Variable variable = lookupVariable(null, name); if (variable != null) { return true; @@ -153,7 +167,7 @@ public class Locals { } /** Looks up a method. Returns null if the method does not exist. */ - public final Method getMethod(MethodKey key) { + public Method getMethod(MethodKey key) { Method method = lookupMethod(key); if (method != null) { return method; @@ -165,7 +179,7 @@ public class Locals { } /** Creates a new variable. Throws IAE if the variable has already been defined (even in a parent) or reserved. */ - public final Variable addVariable(Location location, Type type, String name, boolean readonly) { + public Variable addVariable(Location location, Type type, String name, boolean readonly) { if (hasVariable(name)) { throw location.createError(new IllegalArgumentException("Variable [" + name + "] is already defined.")); } @@ -196,23 +210,23 @@ public class Locals { // return type of this scope private final Type returnType; // next slot number to assign - int nextSlotNumber; + private int nextSlotNumber; // variable name -> variable - Map variables; + private Map variables; // method name+arity -> methods - Map methods; + private Map methods; /** * Create a new Locals */ - Locals(Locals parent) { + private Locals(Locals parent) { this(parent, parent.getReturnType()); } /** * Create a new Locals with specified return type */ - Locals(Locals parent, Type returnType) { + private Locals(Locals parent, Type returnType) { this.parent = parent; this.returnType = returnType; if (parent == null) { @@ -223,12 +237,12 @@ public class Locals { } /** Returns the parent scope */ - Locals getParent() { + private Locals getParent() { return parent; } /** Looks up a variable at this scope only. Returns null if the variable does not exist. */ - Variable lookupVariable(Location location, String name) { + private Variable lookupVariable(Location location, String name) { if (variables == null) { return null; } @@ -236,7 +250,7 @@ public class Locals { } /** Looks up a method at this scope only. Returns null if the method does not exist. */ - Method lookupMethod(MethodKey key) { + private Method lookupMethod(MethodKey key) { if (methods == null) { return null; } @@ -245,19 +259,17 @@ public class Locals { /** Defines a variable at this scope internally. */ - Variable defineVariable(Location location, Type type, String name, boolean readonly) { + private Variable defineVariable(Location location, Type type, String name, boolean readonly) { if (variables == null) { variables = new HashMap<>(); } - Variable variable = new Variable(location, name, type, readonly); - variable.slot = getNextSlot(); + Variable variable = new Variable(location, name, type, getNextSlot(), readonly); variables.put(name, variable); // TODO: check result nextSlotNumber += type.type.getSize(); return variable; } - // TODO: make private, thats bogus - public void addMethod(Method method) { + private void addMethod(Method method) { if (methods == null) { methods = new HashMap<>(); } @@ -266,7 +278,7 @@ public class Locals { } - int getNextSlot() { + private int getNextSlot() { return nextSlotNumber; } @@ -274,13 +286,14 @@ public class Locals { public final Location location; public final String name; public final Type type; - int slot = -1; public final boolean readonly; + private final int slot; - public Variable(Location location, String name, Type type, boolean readonly) { + public Variable(Location location, String name, Type type, int slot, boolean readonly) { this.location = location; this.name = name; this.type = type; + this.slot = slot; this.readonly = readonly; } @@ -289,7 +302,7 @@ public class Locals { } } - public static class Parameter { + public static final class Parameter { public final Location location; public final String name; public final Type type; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ANode.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ANode.java index 08092a9e116..55d62108cba 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ANode.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ANode.java @@ -21,6 +21,9 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Location; +import java.util.Objects; +import java.util.Set; + /** * The superclass for all other nodes. */ @@ -31,9 +34,17 @@ public abstract class ANode { final Location location; ANode(Location location) { - this.location = location; + this.location = Objects.requireNonNull(location); } + /** + * Adds all variable names referenced to the variable set. + *

+ * This can be called at any time, e.g. to support lambda capture. + * @param variables set of variables referenced (any scope) + */ + abstract void extractVariables(Set variables); + public RuntimeException createError(RuntimeException exception) { return location.createError(exception); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java index 11b77b0441f..f0f79315c64 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java @@ -24,6 +24,10 @@ import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Type; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; import org.elasticsearch.painless.Operation; @@ -46,9 +50,15 @@ public final class EBinary extends AExpression { public EBinary(Location location, Operation operation, AExpression left, AExpression right) { super(location); - this.operation = operation; - this.left = left; - this.right = right; + this.operation = Objects.requireNonNull(operation); + this.left = Objects.requireNonNull(left); + this.right = Objects.requireNonNull(right); + } + + @Override + void extractVariables(Set variables) { + left.extractVariables(variables); + right.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java index 9e39ca712f5..d707cc811f9 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBool.java @@ -25,6 +25,10 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Operation; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -39,9 +43,15 @@ public final class EBool extends AExpression { public EBool(Location location, Operation operation, AExpression left, AExpression right) { super(location); - this.operation = operation; - this.left = left; - this.right = right; + this.operation = Objects.requireNonNull(operation); + this.left = Objects.requireNonNull(left); + this.right = Objects.requireNonNull(right); + } + + @Override + void extractVariables(Set variables) { + left.extractVariables(variables); + right.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java index a152422fac4..dc25bb0ed44 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBoolean.java @@ -25,6 +25,8 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import java.util.Set; + /** * Represents a boolean constant. */ @@ -35,6 +37,9 @@ public final class EBoolean extends AExpression { this.constant = constant; } + + @Override + void extractVariables(Set variables) {} @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java index 333787db962..0445a8d20f5 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java @@ -34,32 +34,39 @@ import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; import static org.elasticsearch.painless.WriterConstants.LAMBDA_BOOTSTRAP_HANDLE; import java.lang.invoke.LambdaMetafactory; +import java.util.Objects; +import java.util.Set; /** * Represents a capturing function reference. */ public class ECapturingFunctionRef extends AExpression implements ILambda { - public final String type; + public final String variable; public final String call; private FunctionRef ref; Variable captured; String defPointer; - public ECapturingFunctionRef(Location location, String type, String call) { + public ECapturingFunctionRef(Location location, String variable, String call) { super(location); - this.type = type; - this.call = call; + this.variable = Objects.requireNonNull(variable); + this.call = Objects.requireNonNull(call); + } + + @Override + void extractVariables(Set variables) { + variables.add(variable); } @Override void analyze(Locals variables) { - captured = variables.getVariable(location, type); + captured = variables.getVariable(location, variable); if (expected == null) { if (captured.type.sort == Definition.Sort.DEF) { // dynamic implementation - defPointer = "D" + type + "." + call + ",1"; + defPointer = "D" + variable + "." + call + ",1"; } else { // typed implementation defPointer = "S" + captured.type.name + "." + call + ",1"; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java index 1073125c637..c7dda568ff5 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECast.java @@ -20,6 +20,10 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition.Cast; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; @@ -40,9 +44,13 @@ final class ECast extends AExpression { super(location); this.type = null; - this.child = child; - - this.cast = cast; + this.child = Objects.requireNonNull(child); + this.cast = Objects.requireNonNull(cast); + } + + @Override + void extractVariables(Set variables) { + child.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java index b249cf4511e..9e34da7ea64 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java @@ -32,6 +32,8 @@ import org.elasticsearch.painless.MethodWriter; import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.Set; /** * Represents the entirety of a variable/method chain for read/write operations. @@ -59,12 +61,22 @@ public final class EChain extends AExpression { boolean pre, boolean post, Operation operation, AExpression expression) { super(location); - this.links = links; + this.links = Objects.requireNonNull(links); this.pre = pre; this.post = post; this.operation = operation; this.expression = expression; } + + @Override + void extractVariables(Set variables) { + for (ALink link : links) { + link.extractVariables(variables); + } + if (expression != null) { + expression.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java index 53684a19005..2fcda21c4ec 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java @@ -29,6 +29,10 @@ import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Operation; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; import static org.elasticsearch.painless.WriterConstants.OBJECTS_TYPE; @@ -48,9 +52,15 @@ public final class EComp extends AExpression { public EComp(Location location, Operation operation, AExpression left, AExpression right) { super(location); - this.operation = operation; - this.left = left; - this.right = right; + this.operation = Objects.requireNonNull(operation); + this.left = Objects.requireNonNull(left); + this.right = Objects.requireNonNull(right); + } + + @Override + void extractVariables(Set variables) { + left.extractVariables(variables); + right.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java index 600626348dd..e05419e1c52 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConditional.java @@ -26,6 +26,10 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.AnalyzerCaster; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -40,9 +44,16 @@ public final class EConditional extends AExpression { public EConditional(Location location, AExpression condition, AExpression left, AExpression right) { super(location); - this.condition = condition; - this.left = left; - this.right = right; + this.condition = Objects.requireNonNull(condition); + this.left = Objects.requireNonNull(left); + this.right = Objects.requireNonNull(right); + } + + @Override + void extractVariables(Set variables) { + condition.extractVariables(variables); + left.extractVariables(variables); + right.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java index b037d25c2d6..c5e10a340d6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EConstant.java @@ -22,6 +22,9 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Sort; + +import java.util.Set; + import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -37,6 +40,9 @@ final class EConstant extends AExpression { this.constant = constant; } + + @Override + void extractVariables(Set variables) {} @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java index efa453605cb..e93b63c3bcd 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EDecimal.java @@ -25,8 +25,11 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import java.util.Objects; +import java.util.Set; + /** - * Respresents a decimal constant. + * Represents a decimal constant. */ public final class EDecimal extends AExpression { @@ -35,8 +38,11 @@ public final class EDecimal extends AExpression { public EDecimal(Location location, String value) { super(location); - this.value = value; + this.value = Objects.requireNonNull(value); } + + @Override + void extractVariables(Set variables) {} @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java index 1c186faaeeb..71ad952baff 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EExplicit.java @@ -25,6 +25,9 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import java.util.Objects; +import java.util.Set; + /** * Represents an explicit cast. */ @@ -36,8 +39,13 @@ public final class EExplicit extends AExpression { public EExplicit(Location location, String type, AExpression child) { super(location); - this.type = type; - this.child = child; + this.type = Objects.requireNonNull(type); + this.child = Objects.requireNonNull(child); + } + + @Override + void extractVariables(Set variables) { + child.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java index 856a876550c..298b84ffe29 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java @@ -32,6 +32,8 @@ import org.objectweb.asm.Type; import static org.elasticsearch.painless.WriterConstants.LAMBDA_BOOTSTRAP_HANDLE; import java.lang.invoke.LambdaMetafactory; +import java.util.Objects; +import java.util.Set; /** * Represents a function reference. @@ -46,9 +48,12 @@ public class EFunctionRef extends AExpression implements ILambda { public EFunctionRef(Location location, String type, String call) { super(location); - this.type = type; - this.call = call; + this.type = Objects.requireNonNull(type); + this.call = Objects.requireNonNull(call); } + + @Override + void extractVariables(Set variables) {} @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java index d0b531c74d3..8adae6607a9 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java @@ -23,13 +23,23 @@ import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Locals.Variable; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; +import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.node.SFunction.FunctionReserved; +import org.elasticsearch.painless.Definition; +import org.elasticsearch.painless.FunctionRef; import org.elasticsearch.painless.Globals; +import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; +import java.lang.invoke.LambdaMetafactory; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Objects; +import java.util.Set; + +import static org.elasticsearch.painless.WriterConstants.LAMBDA_BOOTSTRAP_HANDLE; public class ELambda extends AExpression implements ILambda { final String name; @@ -37,58 +47,147 @@ public class ELambda extends AExpression implements ILambda { final List paramTypeStrs; final List paramNameStrs; final List statements; + // desugared synthetic method (lambda body) SFunction desugared; - // method ref (impl detail) - ILambda impl; + // captured variables + List captures; + // static parent, static lambda + FunctionRef ref; + // dynamic parent, deferred until link time + String defPointer; public ELambda(String name, FunctionReserved reserved, Location location, List paramTypes, List paramNames, List statements) { super(location); - this.name = name; - this.reserved = reserved; + this.name = Objects.requireNonNull(name); + this.reserved = Objects.requireNonNull(reserved); this.paramTypeStrs = Collections.unmodifiableList(paramTypes); this.paramNameStrs = Collections.unmodifiableList(paramNames); this.statements = Collections.unmodifiableList(statements); } + + @Override + void extractVariables(Set variables) { + for (AStatement statement : statements) { + statement.extractVariables(variables); + } + } @Override void analyze(Locals locals) { + // gather any variables used by the lambda body first. + Set variables = new HashSet<>(); + for (AStatement statement : statements) { + statement.extractVariables(variables); + } + // any of those variables defined in our scope need to be captured + captures = new ArrayList<>(); + for (String variable : variables) { + if (locals.hasVariable(variable)) { + captures.add(locals.getVariable(location, variable)); + } + } + // prepend capture list to lambda's arguments + List paramTypes = new ArrayList<>(); + List paramNames = new ArrayList<>(); + for (Variable var : captures) { + paramTypes.add(var.type.name); + paramNames.add(var.name); + } + paramTypes.addAll(paramTypeStrs); + paramNames.addAll(paramNameStrs); + // desugar lambda body into a synthetic method desugared = new SFunction(reserved, location, "def", name, - paramTypeStrs, paramNameStrs, statements, true); + paramTypes, paramNames, statements, true); desugared.generate(); - List captures = new ArrayList<>(); - desugared.analyze(Locals.newLambdaScope(locals.getProgramScope(), desugared.parameters, captures)); + desugared.analyze(Locals.newLambdaScope(locals.getProgramScope(), desugared.parameters, + captures.size(), reserved.getMaxLoopCounter())); - // setup reference - EFunctionRef ref = new EFunctionRef(location, "this", name); - ref.expected = expected; - // hack, create a new scope, with our method, so the ref can see it (impl detail) - locals = Locals.newLocalScope(locals); - locals.addMethod(desugared.method); - ref.analyze(locals); - actual = ref.actual; - impl = ref; + // setup method reference to synthetic method + if (expected == null) { + ref = null; + actual = Definition.getType("String"); + defPointer = "Sthis." + name + "," + captures.size(); + } else { + defPointer = null; + try { + Method interfaceMethod = expected.struct.getFunctionalMethod(); + if (interfaceMethod == null) { + throw new IllegalArgumentException("Cannot pass lambda to [" + expected.name + + "], not a functional interface"); + } + Class captureClasses[] = new Class[captures.size()]; + for (int i = 0; i < captures.size(); i++) { + captureClasses[i] = captures.get(i).type.clazz; + } + ref = new FunctionRef(expected, interfaceMethod, desugared.method, captureClasses); + } catch (IllegalArgumentException e) { + throw createError(e); + } + actual = expected; + } } @Override void write(MethodWriter writer, Globals globals) { - AExpression expr = (AExpression) impl; - expr.write(writer, globals); + writer.writeDebugInfo(location); + + if (ref != null) { + writer.writeDebugInfo(location); + // load captures + for (Variable capture : captures) { + writer.visitVarInsn(capture.type.type.getOpcode(Opcodes.ILOAD), capture.getSlot()); + } + // convert MethodTypes to asm Type for the constant pool. + String invokedType = ref.invokedType.toMethodDescriptorString(); + Type samMethodType = Type.getMethodType(ref.samMethodType.toMethodDescriptorString()); + Type interfaceType = Type.getMethodType(ref.interfaceMethodType.toMethodDescriptorString()); + if (ref.needsBridges()) { + writer.invokeDynamic(ref.invokedName, + invokedType, + LAMBDA_BOOTSTRAP_HANDLE, + samMethodType, + ref.implMethodASM, + samMethodType, + LambdaMetafactory.FLAG_BRIDGES, + 1, + interfaceType); + } else { + writer.invokeDynamic(ref.invokedName, + invokedType, + LAMBDA_BOOTSTRAP_HANDLE, + samMethodType, + ref.implMethodASM, + samMethodType, + 0); + } + } else { + // placeholder + writer.push((String)null); + // load captures + for (Variable capture : captures) { + writer.visitVarInsn(capture.type.type.getOpcode(Opcodes.ILOAD), capture.getSlot()); + } + } + // add synthetic method to the queue to be written globals.addSyntheticMethod(desugared); } @Override public String getPointer() { - return impl.getPointer(); + return defPointer; } @Override public Type[] getCaptures() { - return impl.getCaptures(); + Type[] types = new Type[captures.size()]; + for (int i = 0; i < types.length; i++) { + types[i] = captures.get(i).type.type; + } + return types; } - } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java index 0a1242e6507..ad6562c0e14 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENull.java @@ -24,6 +24,9 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Opcodes; + +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -34,6 +37,9 @@ public final class ENull extends AExpression { public ENull(Location location) { super(location); } + + @Override + void extractVariables(Set variables) {} @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java index e2314880448..e9a28a1e06a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ENumeric.java @@ -23,6 +23,10 @@ import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Sort; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -37,9 +41,12 @@ public final class ENumeric extends AExpression { public ENumeric(Location location, String value, int radix) { super(location); - this.value = value; + this.value = Objects.requireNonNull(value); this.radix = radix; } + + @Override + void extractVariables(Set variables) {} @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java index f74b91dd5bc..30b5310da4b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java @@ -29,6 +29,10 @@ import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Operation; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; @@ -45,8 +49,13 @@ public final class EUnary extends AExpression { public EUnary(Location location, Operation operation, AExpression child) { super(location); - this.operation = operation; - this.child = child; + this.operation = Objects.requireNonNull(operation); + this.child = Objects.requireNonNull(child); + } + + @Override + void extractVariables(Set variables) { + child.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LArrayLength.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LArrayLength.java index 1a240747d73..a2970ca2e53 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LArrayLength.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LArrayLength.java @@ -25,6 +25,9 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import java.util.Objects; +import java.util.Set; + /** * Represents an array length field load. */ @@ -35,8 +38,11 @@ public final class LArrayLength extends ALink { LArrayLength(Location location, String value) { super(location, -1); - this.value = value; + this.value = Objects.requireNonNull(value); } + + @Override + void extractVariables(Set variables) {} @Override ALink analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LBrace.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LBrace.java index e8c23bf3857..16b9b8c5d44 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LBrace.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LBrace.java @@ -28,6 +28,8 @@ import org.elasticsearch.painless.MethodWriter; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; /** * Represents an array load/store or defers to possible shortcuts. @@ -39,7 +41,12 @@ public final class LBrace extends ALink { public LBrace(Location location, AExpression index) { super(location, 2); - this.index = index; + this.index = Objects.requireNonNull(index); + } + + @Override + void extractVariables(Set variables) { + index.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java index 34ad0343aa9..124755780cb 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java @@ -29,9 +29,11 @@ import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; import java.util.List; +import java.util.Objects; +import java.util.Set; /** - * Represents a method call or deferes to a def call. + * Represents a method call or defers to a def call. */ public final class LCallInvoke extends ALink { @@ -43,8 +45,15 @@ public final class LCallInvoke extends ALink { public LCallInvoke(Location location, String name, List arguments) { super(location, -1); - this.name = name; - this.arguments = arguments; + this.name = Objects.requireNonNull(name); + this.arguments = Objects.requireNonNull(arguments); + } + + @Override + void extractVariables(Set variables) { + for (AExpression argument : arguments) { + argument.extractVariables(variables); + } } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallLocal.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallLocal.java index 4503692b48d..7aa46f004d6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallLocal.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallLocal.java @@ -27,6 +27,8 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; import java.util.List; +import java.util.Objects; +import java.util.Set; import static org.elasticsearch.painless.WriterConstants.CLASS_TYPE; @@ -43,8 +45,15 @@ public class LCallLocal extends ALink { public LCallLocal(Location location, String name, List arguments) { super(location, -1); - this.name = name; - this.arguments = arguments; + this.name = Objects.requireNonNull(name); + this.arguments = Objects.requireNonNull(arguments); + } + + @Override + void extractVariables(Set variables) { + for (AExpression argument : arguments) { + argument.extractVariables(variables); + } } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCast.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCast.java index bf900cedafc..86dbdda24c4 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCast.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCast.java @@ -23,6 +23,9 @@ import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Cast; + +import java.util.Set; + import org.elasticsearch.painless.AnalyzerCaster; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -41,6 +44,9 @@ public final class LCast extends ALink { this.type = type; } + + @Override + void extractVariables(Set variables) {} @Override ALink analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java index 02fbb2000f2..7c47103be37 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java @@ -25,6 +25,10 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Type; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; @@ -39,7 +43,12 @@ final class LDefArray extends ALink implements IDefLink { LDefArray(Location location, AExpression index) { super(location, 2); - this.index = index; + this.index = Objects.requireNonNull(index); + } + + @Override + void extractVariables(Set variables) { + index.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java index 716b26d6687..d216eacae19 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java @@ -29,6 +29,8 @@ import org.objectweb.asm.Type; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.Set; import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; @@ -45,8 +47,15 @@ final class LDefCall extends ALink implements IDefLink { LDefCall(Location location, String name, List arguments) { super(location, -1); - this.name = name; - this.arguments = arguments; + this.name = Objects.requireNonNull(name); + this.arguments = Objects.requireNonNull(arguments); + } + + @Override + void extractVariables(Set variables) { + for (AExpression argument : arguments) { + argument.extractVariables(variables); + } } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java index 125b2bee6fc..6f9f7e24bd2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java @@ -25,6 +25,10 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Type; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; @@ -39,9 +43,11 @@ final class LDefField extends ALink implements IDefLink { LDefField(Location location, String value) { super(location, 1); - this.value = value; + this.value = Objects.requireNonNull(value); } + @Override + void extractVariables(Set variables) {} @Override ALink analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LField.java index 9fc48c009a2..30d0a033746 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LField.java @@ -30,6 +30,8 @@ import org.elasticsearch.painless.MethodWriter; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; /** * Represents a field load/store or defers to a possible shortcuts. @@ -43,8 +45,11 @@ public final class LField extends ALink { public LField(Location location, String value) { super(location, 1); - this.value = value; + this.value = Objects.requireNonNull(value); } + + @Override + void extractVariables(Set variables) {} @Override ALink analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LListShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LListShortcut.java index 1cd5620cc17..f2863ce3396 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LListShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LListShortcut.java @@ -24,6 +24,10 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -39,7 +43,12 @@ final class LListShortcut extends ALink { LListShortcut(Location location, AExpression index) { super(location, 2); - this.index = index; + this.index = Objects.requireNonNull(index); + } + + @Override + void extractVariables(Set variables) { + index.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LMapShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LMapShortcut.java index 05c2192b870..3bc9ab57a37 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LMapShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LMapShortcut.java @@ -24,6 +24,10 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -39,7 +43,12 @@ final class LMapShortcut extends ALink { LMapShortcut(Location location, AExpression index) { super(location, 2); - this.index = index; + this.index = Objects.requireNonNull(index); + } + + @Override + void extractVariables(Set variables) { + index.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewArray.java index 312cbf925e1..cf83599210f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewArray.java @@ -27,6 +27,8 @@ import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; import java.util.List; +import java.util.Objects; +import java.util.Set; /** * Represents an array instantiation. @@ -39,8 +41,15 @@ public final class LNewArray extends ALink { public LNewArray(Location location, String type, List arguments) { super(location, -1); - this.type = type; - this.arguments = arguments; + this.type = Objects.requireNonNull(type); + this.arguments = Objects.requireNonNull(arguments); + } + + @Override + void extractVariables(Set variables) { + for (AExpression argument : arguments) { + argument.extractVariables(variables); + } } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewObj.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewObj.java index 0b28a308e19..0ac2762f336 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewObj.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LNewObj.java @@ -29,6 +29,8 @@ import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; import java.util.List; +import java.util.Objects; +import java.util.Set; /** * Represents and object instantiation. @@ -43,8 +45,15 @@ public final class LNewObj extends ALink { public LNewObj(Location location, String type, List arguments) { super(location, -1); - this.type = type; - this.arguments = arguments; + this.type = Objects.requireNonNull(type); + this.arguments = Objects.requireNonNull(arguments); + } + + @Override + void extractVariables(Set variables) { + for (AExpression argument : arguments) { + argument.extractVariables(variables); + } } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LRegex.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LRegex.java index 8727f992242..c737c761cf2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LRegex.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LRegex.java @@ -24,6 +24,7 @@ import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; +import java.util.Set; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -54,6 +55,9 @@ public final class LRegex extends ALink { throw createError(e); } } + + @Override + void extractVariables(Set variables) {} @Override ALink analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LShortcut.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LShortcut.java index efaf02bb601..7f97b446382 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LShortcut.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LShortcut.java @@ -25,6 +25,10 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Struct; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -41,8 +45,11 @@ final class LShortcut extends ALink { LShortcut(Location location, String value) { super(location, 1); - this.value = value; + this.value = Objects.requireNonNull(value); } + + @Override + void extractVariables(Set variables) {} @Override ALink analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LStatic.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LStatic.java index 3a7c9a35fe5..d9077a4446f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LStatic.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LStatic.java @@ -23,6 +23,10 @@ import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.Locals; /** @@ -35,8 +39,11 @@ public final class LStatic extends ALink { public LStatic(Location location, String type) { super(location, 0); - this.type = type; + this.type = Objects.requireNonNull(type); } + + @Override + void extractVariables(Set variables) {} @Override ALink analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LString.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LString.java index fac9d413ad7..ab45c0f3a8e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LString.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LString.java @@ -25,6 +25,9 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import java.util.Objects; +import java.util.Set; + /** * Represents a string constant. */ @@ -33,8 +36,11 @@ public final class LString extends ALink { public LString(Location location, String string) { super(location, -1); - this.string = string; + this.string = Objects.requireNonNull(string); } + + @Override + void extractVariables(Set variables) {} @Override ALink analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LVariable.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LVariable.java index ad9ba9dfbf6..4f016349c24 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LVariable.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LVariable.java @@ -26,6 +26,9 @@ import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Locals.Variable; import org.objectweb.asm.Opcodes; +import java.util.Objects; +import java.util.Set; + /** * Represents a variable load/store. */ @@ -38,7 +41,12 @@ public final class LVariable extends ALink { public LVariable(Location location, String name) { super(location, 0); - this.name = name; + this.name = Objects.requireNonNull(name); + } + + @Override + void extractVariables(Set variables) { + variables.add(name); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java index 7d459f27504..e688f0acec0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBlock.java @@ -26,6 +26,7 @@ import org.elasticsearch.painless.MethodWriter; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Represents a set of statements as a branch of control-flow. @@ -39,6 +40,13 @@ public final class SBlock extends AStatement { this.statements = Collections.unmodifiableList(statements); } + + @Override + void extractVariables(Set variables) { + for (AStatement statement : statements) { + statement.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java index c791faeadd6..62560d1bd4e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SBreak.java @@ -24,6 +24,8 @@ import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; +import java.util.Set; + /** * Represents a break statement. */ @@ -32,6 +34,9 @@ public final class SBreak extends AStatement { public SBreak(Location location) { super(location); } + + @Override + void extractVariables(Set variables) {} @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java index 8632c0eea6d..783af3d0022 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SCatch.java @@ -27,6 +27,10 @@ import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Locals.Variable; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -47,10 +51,18 @@ public final class SCatch extends AStatement { public SCatch(Location location, String type, String name, SBlock block) { super(location); - this.type = type; - this.name = name; + this.type = Objects.requireNonNull(type); + this.name = Objects.requireNonNull(name); this.block = block; } + + @Override + void extractVariables(Set variables) { + variables.add(name); + if (block != null) { + block.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java index e70f625bb3d..98ac804cc3a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SContinue.java @@ -24,6 +24,8 @@ import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.MethodWriter; +import java.util.Set; + /** * Represents a continue statement. */ @@ -32,6 +34,9 @@ public final class SContinue extends AStatement { public SContinue(Location location) { super(location); } + + @Override + void extractVariables(Set variables) {} @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java index 58ff09e45d8..d0dae5a68ac 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclBlock.java @@ -26,6 +26,7 @@ import org.elasticsearch.painless.MethodWriter; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Represents a series of declarations. @@ -39,6 +40,13 @@ public final class SDeclBlock extends AStatement { this.declarations = Collections.unmodifiableList(declarations); } + + @Override + void extractVariables(Set variables) { + for (SDeclaration declaration : declarations) { + declaration.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java index c19adfd699e..de856722a0a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDeclaration.java @@ -26,6 +26,10 @@ import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.Locals.Variable; import org.objectweb.asm.Opcodes; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -42,10 +46,18 @@ public final class SDeclaration extends AStatement { public SDeclaration(Location location, String type, String name, AExpression expression) { super(location); - this.type = type; - this.name = name; + this.type = Objects.requireNonNull(type); + this.name = Objects.requireNonNull(name); this.expression = expression; } + + @Override + void extractVariables(Set variables) { + variables.add(name); + if (expression != null) { + expression.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java index 3b94f5799ea..e214703daf4 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SDo.java @@ -24,6 +24,10 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -37,9 +41,17 @@ public final class SDo extends AStatement { public SDo(Location location, SBlock block, AExpression condition) { super(location); - this.condition = condition; + this.condition = Objects.requireNonNull(condition); this.block = block; } + + @Override + void extractVariables(Set variables) { + condition.extractVariables(variables); + if (block != null) { + block.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java index 403b377ea9c..3469f51639b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java @@ -35,6 +35,9 @@ import org.elasticsearch.painless.Locals.Variable; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; +import java.util.Objects; +import java.util.Set; + import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; import static org.elasticsearch.painless.WriterConstants.ITERATOR_HASNEXT; import static org.elasticsearch.painless.WriterConstants.ITERATOR_NEXT; @@ -66,11 +69,20 @@ public class SEach extends AStatement { public SEach(Location location, String type, String name, AExpression expression, SBlock block) { super(location); - this.type = type; - this.name = name; - this.expression = expression; + this.type = Objects.requireNonNull(type); + this.name = Objects.requireNonNull(name); + this.expression = Objects.requireNonNull(expression); this.block = block; } + + @Override + void extractVariables(Set variables) { + variables.add(name); + expression.extractVariables(variables); + if (block != null) { + block.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java index c6cf0a47c8f..94eb180ea03 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SExpression.java @@ -20,6 +20,10 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition.Type; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Globals; @@ -36,7 +40,12 @@ public final class SExpression extends AStatement { public SExpression(Location location, AExpression expression) { super(location); - this.expression = expression; + this.expression = Objects.requireNonNull(expression); + } + + @Override + void extractVariables(Set variables) { + expression.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java index b2cf1da2594..06ad19d204d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFor.java @@ -24,6 +24,9 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -44,6 +47,22 @@ public final class SFor extends AStatement { this.afterthought = afterthought; this.block = block; } + + @Override + void extractVariables(Set variables) { + if (initializer != null) { + initializer.extractVariables(variables); + } + if (condition != null) { + condition.extractVariables(variables); + } + if (afterthought != null) { + afterthought.extractVariables(variables); + } + if (block != null) { + block.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java index 8d3db7f811a..629f76cdd52 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java @@ -41,6 +41,8 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; +import java.util.Set; import static org.elasticsearch.painless.WriterConstants.CLASS_TYPE; @@ -67,14 +69,24 @@ public class SFunction extends AStatement { List paramNames, List statements, boolean synthetic) { super(location); - this.reserved = reserved; - this.rtnTypeStr = rtnType; - this.name = name; + this.reserved = Objects.requireNonNull(reserved); + this.rtnTypeStr = Objects.requireNonNull(rtnType); + this.name = Objects.requireNonNull(name); this.paramTypeStrs = Collections.unmodifiableList(paramTypes); this.paramNameStrs = Collections.unmodifiableList(paramNames); this.statements = Collections.unmodifiableList(statements); this.synthetic = synthetic; } + + @Override + void extractVariables(Set variables) { + for (String paramName : paramNameStrs) { + variables.add(paramName); + } + for (AStatement statement : statements) { + statement.extractVariables(variables); + } + } void generate() { try { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java index 1b0c0ffb348..eb862b1177a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIf.java @@ -24,6 +24,10 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -37,9 +41,17 @@ public final class SIf extends AStatement { public SIf(Location location, AExpression condition, SBlock ifblock) { super(location); - this.condition = condition; + this.condition = Objects.requireNonNull(condition); this.ifblock = ifblock; } + + @Override + void extractVariables(Set variables) { + condition.extractVariables(variables); + if (ifblock != null) { + ifblock.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java index 612969acfff..8296ddcada0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SIfElse.java @@ -24,6 +24,10 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -38,10 +42,21 @@ public final class SIfElse extends AStatement { public SIfElse(Location location, AExpression condition, SBlock ifblock, SBlock elseblock) { super(location); - this.condition = condition; + this.condition = Objects.requireNonNull(condition); this.ifblock = ifblock; this.elseblock = elseblock; } + + @Override + void extractVariables(Set variables) { + condition.extractVariables(variables); + if (ifblock != null) { + ifblock.extractVariables(variables); + } + if (elseblock != null) { + elseblock.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java index 2c46b3ecfaf..36e629ca6d8 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SReturn.java @@ -24,6 +24,9 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import java.util.Objects; +import java.util.Set; + /** * Represents a return statement. */ @@ -34,7 +37,12 @@ public final class SReturn extends AStatement { public SReturn(Location location, AExpression expression) { super(location); - this.expression = expression; + this.expression = Objects.requireNonNull(expression); + } + + @Override + void extractVariables(Set variables) { + expression.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java index 5e932072ce1..1a47cfeba36 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java @@ -43,6 +43,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; import static org.elasticsearch.painless.WriterConstants.BASE_CLASS_TYPE; import static org.elasticsearch.painless.WriterConstants.CLASS_TYPE; @@ -71,10 +73,10 @@ public final class SSource extends AStatement { List functions, Globals globals, List statements) { super(location); - this.name = name; - this.source = source; + this.name = Objects.requireNonNull(name); + this.source = Objects.requireNonNull(source); this.debugStream = debugStream; - this.reserved = reserved; + this.reserved = Objects.requireNonNull(reserved); // process any synthetic functions generated by walker (because right now, thats still easy) functions.addAll(globals.getSyntheticMethods().values()); globals.getSyntheticMethods().clear(); @@ -82,6 +84,16 @@ public final class SSource extends AStatement { this.statements = Collections.unmodifiableList(statements); this.globals = globals; } + + @Override + void extractVariables(Set variables) { + for (AStatement statement : statements) { + statement.extractVariables(variables); + } + for (SFunction function : functions) { + function.extractVariables(variables); + } + } public void analyze() { Map methods = new HashMap<>(); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java index ffa1b89dfe2..c78e0503f30 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SThrow.java @@ -25,6 +25,9 @@ import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import java.util.Objects; +import java.util.Set; + /** * Represents a throw statement. */ @@ -35,7 +38,12 @@ public final class SThrow extends AStatement { public SThrow(Location location, AExpression expression) { super(location); - this.expression = expression; + this.expression = Objects.requireNonNull(expression); + } + + @Override + void extractVariables(Set variables) { + expression.extractVariables(variables); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java index 0295d32ae35..1986b5eeb66 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/STry.java @@ -27,6 +27,7 @@ import org.elasticsearch.painless.MethodWriter; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Represents the try block as part of a try-catch block. @@ -42,6 +43,16 @@ public final class STry extends AStatement { this.block = block; this.catches = Collections.unmodifiableList(catches); } + + @Override + void extractVariables(Set variables) { + if (block != null) { + block.extractVariables(variables); + } + for (SCatch expr : catches) { + expr.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java index 39b48781b46..dff8ae2592f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SWhile.java @@ -24,6 +24,10 @@ import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; + +import java.util.Objects; +import java.util.Set; + import org.elasticsearch.painless.MethodWriter; /** @@ -37,9 +41,17 @@ public final class SWhile extends AStatement { public SWhile(Location location, AExpression condition, SBlock block) { super(location); - this.condition = condition; + this.condition = Objects.requireNonNull(condition); this.block = block; } + + @Override + void extractVariables(Set variables) { + condition.extractVariables(variables); + if (block != null) { + block.extractVariables(variables); + } + } @Override void analyze(Locals locals) { diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java index dada9a9bc37..22abb8f5255 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java @@ -103,4 +103,34 @@ public class LambdaTests extends ScriptTestCase { "}" + "return sum;")); } + + public void testCapture() { + assertEquals(5, exec("int x = 5; return Optional.empty().orElseGet(() -> x);")); + } + + public void testTwoCaptures() { + assertEquals("1test", exec("int x = 1; String y = 'test'; return Optional.empty().orElseGet(() -> x + y);")); + } + + public void testCapturesAreReadOnly() { + IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { + exec("List l = new ArrayList(); l.add(1); l.add(1); " + + "return l.stream().mapToInt(x -> { l = null; return x + 1 }).sum();"); + }); + assertTrue(expected.getMessage().contains("is read-only")); + } + + public void testOnlyCapturesAreReadOnly() { + assertEquals(4, exec("List l = new ArrayList(); l.add(1); l.add(1); " + + "return l.stream().mapToInt(x -> { x += 1; return x }).sum();")); + } + + public void testCaptureDef() { + assertEquals(5, exec("int x = 5; def y = Optional.empty(); y.orElseGet(() -> x);")); + } + + public void testNestedCapture() { + assertEquals(1, exec("boolean x = false; int y = 1;" + + "return Optional.empty().orElseGet(() -> x ? 5 : Optional.empty().orElseGet(() -> y));")); + } } From 4cb2bb635b580eaa6377d53aa1e8c6f742698452 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sat, 18 Jun 2016 17:06:18 +0200 Subject: [PATCH 45/87] Remove forked joda time BaseDateTime class (#18953) This class was forked in 0.20 to remove a volatile keyword. While there is no issue attached to the commit, no evidence of the criticality of the change nor does it seem to be correct since we set this value internally as well I think this class should be used as is from joda time even if we have to pay the price of volatile reads. We can't do 3rd party optimization in our codebase that way it just not maintainable. This was added in 2280915d3cc3e9fe0fe5fab57ae57774e9044af7 --- .../java/org/joda/time/base/BaseDateTime.java | 345 ------------------ 1 file changed, 345 deletions(-) delete mode 100644 core/src/main/java/org/joda/time/base/BaseDateTime.java diff --git a/core/src/main/java/org/joda/time/base/BaseDateTime.java b/core/src/main/java/org/joda/time/base/BaseDateTime.java deleted file mode 100644 index 29c34246249..00000000000 --- a/core/src/main/java/org/joda/time/base/BaseDateTime.java +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Copyright 2001-2011 Stephen Colebourne - * - * Licensed 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.joda.time.base; - -import org.joda.time.Chronology; -import org.joda.time.DateTimeUtils; -import org.joda.time.DateTimeZone; -import org.joda.time.ReadableDateTime; -import org.joda.time.chrono.ISOChronology; -import org.joda.time.convert.ConverterManager; -import org.joda.time.convert.InstantConverter; - -/** - * BaseDateTime is an abstract implementation of ReadableDateTime that stores - * data in long and Chronology fields. - *

- * This class should generally not be used directly by API users. - * The {@link ReadableDateTime} interface should be used when different - * kinds of date/time objects are to be referenced. - *

- * BaseDateTime subclasses may be mutable and not thread-safe. - * - * @author Stephen Colebourne - * @author Kandarp Shah - * @author Brian S O'Neill - * @since 1.0 - */ -public abstract class BaseDateTime - extends AbstractDateTime - implements ReadableDateTime { - /** - * The millis from 1970-01-01T00:00:00Z - */ - // THIS IS THE ES CHANGE not to have it volatile... - private long iMillis; - /** - * The chronology to use - */ - private volatile Chronology iChronology; - - //----------------------------------------------------------------------- - - /** - * Constructs an instance set to the current system millisecond time - * using ISOChronology in the default time zone. - */ - public BaseDateTime() { - this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance()); - } - - /** - * Constructs an instance set to the current system millisecond time - * using ISOChronology in the specified time zone. - *

- * If the specified time zone is null, the default zone is used. - * - * @param zone the time zone, null means default zone - */ - public BaseDateTime(DateTimeZone zone) { - this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance(zone)); - } - - /** - * Constructs an instance set to the current system millisecond time - * using the specified chronology. - *

- * If the chronology is null, ISOChronology - * in the default time zone is used. - * - * @param chronology the chronology, null means ISOChronology in default zone - */ - public BaseDateTime(Chronology chronology) { - this(DateTimeUtils.currentTimeMillis(), chronology); - } - - //----------------------------------------------------------------------- - - /** - * Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z - * using ISOChronology in the default time zone. - * - * @param instant the milliseconds from 1970-01-01T00:00:00Z - */ - public BaseDateTime(long instant) { - this(instant, ISOChronology.getInstance()); - } - - /** - * Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z - * using ISOChronology in the specified time zone. - *

- * If the specified time zone is null, the default zone is used. - * - * @param instant the milliseconds from 1970-01-01T00:00:00Z - * @param zone the time zone, null means default zone - */ - public BaseDateTime(long instant, DateTimeZone zone) { - this(instant, ISOChronology.getInstance(zone)); - } - - /** - * Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z - * using the specified chronology. - *

- * If the chronology is null, ISOChronology - * in the default time zone is used. - * - * @param instant the milliseconds from 1970-01-01T00:00:00Z - * @param chronology the chronology, null means ISOChronology in default zone - */ - public BaseDateTime(long instant, Chronology chronology) { - super(); - iChronology = checkChronology(chronology); - iMillis = checkInstant(instant, iChronology); - // validate not over maximum - if (iChronology.year().isSupported()) { - iChronology.year().set(iMillis, iChronology.year().get(iMillis)); - } - } - - //----------------------------------------------------------------------- - - /** - * Constructs an instance from an Object that represents a datetime, - * forcing the time zone to that specified. - *

- * If the object contains no chronology, ISOChronology is used. - * If the specified time zone is null, the default zone is used. - *

- * The recognised object types are defined in - * {@link org.joda.time.convert.ConverterManager ConverterManager} and - * include ReadableInstant, String, Calendar and Date. - * - * @param instant the datetime object - * @param zone the time zone - * @throws IllegalArgumentException if the instant is invalid - */ - public BaseDateTime(Object instant, DateTimeZone zone) { - super(); - InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); - Chronology chrono = checkChronology(converter.getChronology(instant, zone)); - iChronology = chrono; - iMillis = checkInstant(converter.getInstantMillis(instant, chrono), chrono); - } - - /** - * Constructs an instance from an Object that represents a datetime, - * using the specified chronology. - *

- * If the chronology is null, ISO in the default time zone is used. - *

- * The recognised object types are defined in - * {@link org.joda.time.convert.ConverterManager ConverterManager} and - * include ReadableInstant, String, Calendar and Date. - * - * @param instant the datetime object - * @param chronology the chronology - * @throws IllegalArgumentException if the instant is invalid - */ - public BaseDateTime(Object instant, Chronology chronology) { - super(); - InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); - iChronology = checkChronology(converter.getChronology(instant, chronology)); - iMillis = checkInstant(converter.getInstantMillis(instant, chronology), iChronology); - } - - //----------------------------------------------------------------------- - - /** - * Constructs an instance from datetime field values - * using ISOChronology in the default time zone. - * - * @param year the year - * @param monthOfYear the month of the year - * @param dayOfMonth the day of the month - * @param hourOfDay the hour of the day - * @param minuteOfHour the minute of the hour - * @param secondOfMinute the second of the minute - * @param millisOfSecond the millisecond of the second - */ - public BaseDateTime( - int year, - int monthOfYear, - int dayOfMonth, - int hourOfDay, - int minuteOfHour, - int secondOfMinute, - int millisOfSecond) { - this(year, monthOfYear, dayOfMonth, hourOfDay, - minuteOfHour, secondOfMinute, millisOfSecond, ISOChronology.getInstance()); - } - - /** - * Constructs an instance from datetime field values - * using ISOChronology in the specified time zone. - *

- * If the specified time zone is null, the default zone is used. - * - * @param year the year - * @param monthOfYear the month of the year - * @param dayOfMonth the day of the month - * @param hourOfDay the hour of the day - * @param minuteOfHour the minute of the hour - * @param secondOfMinute the second of the minute - * @param millisOfSecond the millisecond of the second - * @param zone the time zone, null means default time zone - */ - public BaseDateTime( - int year, - int monthOfYear, - int dayOfMonth, - int hourOfDay, - int minuteOfHour, - int secondOfMinute, - int millisOfSecond, - DateTimeZone zone) { - this(year, monthOfYear, dayOfMonth, hourOfDay, - minuteOfHour, secondOfMinute, millisOfSecond, ISOChronology.getInstance(zone)); - } - - /** - * Constructs an instance from datetime field values - * using the specified chronology. - *

- * If the chronology is null, ISOChronology - * in the default time zone is used. - * - * @param year the year - * @param monthOfYear the month of the year - * @param dayOfMonth the day of the month - * @param hourOfDay the hour of the day - * @param minuteOfHour the minute of the hour - * @param secondOfMinute the second of the minute - * @param millisOfSecond the millisecond of the second - * @param chronology the chronology, null means ISOChronology in default zone - */ - public BaseDateTime( - int year, - int monthOfYear, - int dayOfMonth, - int hourOfDay, - int minuteOfHour, - int secondOfMinute, - int millisOfSecond, - Chronology chronology) { - super(); - iChronology = checkChronology(chronology); - long instant = iChronology.getDateTimeMillis(year, monthOfYear, dayOfMonth, - hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); - iMillis = checkInstant(instant, iChronology); - } - - //----------------------------------------------------------------------- - - /** - * Checks the specified chronology before storing it, potentially altering it. - * This method must not access any instance variables. - *

- * This implementation converts nulls to ISOChronology in the default zone. - * - * @param chronology the chronology to use, may be null - * @return the chronology to store in this datetime, not null - */ - protected Chronology checkChronology(Chronology chronology) { - return DateTimeUtils.getChronology(chronology); - } - - /** - * Checks the specified instant before storing it, potentially altering it. - * This method must not access any instance variables. - *

- * This implementation simply returns the instant. - * - * @param instant the milliseconds from 1970-01-01T00:00:00Z to round - * @param chronology the chronology to use, not null - * @return the instant to store in this datetime - */ - protected long checkInstant(long instant, Chronology chronology) { - return instant; - } - - //----------------------------------------------------------------------- - - /** - * Gets the milliseconds of the datetime instant from the Java epoch - * of 1970-01-01T00:00:00Z. - * - * @return the number of milliseconds since 1970-01-01T00:00:00Z - */ - @Override - public long getMillis() { - return iMillis; - } - - /** - * Gets the chronology of the datetime. - * - * @return the Chronology that the datetime is using - */ - @Override - public Chronology getChronology() { - return iChronology; - } - - //----------------------------------------------------------------------- - - /** - * Sets the milliseconds of the datetime. - *

- * All changes to the millisecond field occurs via this method. - * Override and block this method to make a subclass immutable. - * - * @param instant the milliseconds since 1970-01-01T00:00:00Z to set the datetime to - */ - protected void setMillis(long instant) { - iMillis = checkInstant(instant, iChronology); - } - - /** - * Sets the chronology of the datetime. - *

- * All changes to the chronology field occurs via this method. - * Override and block this method to make a subclass immutable. - * - * @param chronology the chronology to set - */ - protected void setChronology(Chronology chronology) { - iChronology = checkChronology(chronology); - } - -} From 535a245354c1dd57b46adee0d3c6ffdb8d8c2e63 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Sat, 18 Jun 2016 18:44:54 +0200 Subject: [PATCH 46/87] testSingleBatchSubmission - random numbers don't have to be unique --- .../elasticsearch/cluster/service/ClusterServiceTests.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java index 306eecf81b5..66f96f8cd3a 100644 --- a/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java @@ -23,7 +23,6 @@ import org.apache.log4j.Logger; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterChangedEvent; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateTaskConfig; import org.elasticsearch.cluster.ClusterStateTaskExecutor; @@ -33,7 +32,6 @@ import org.elasticsearch.cluster.NodeConnectionsService; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.OperationRouting; import org.elasticsearch.common.Priority; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.lease.Releasable; @@ -382,7 +380,7 @@ public class ClusterServiceTests extends ESTestCase { final int numOfTasks = randomInt(10); final CountDownLatch latch = new CountDownLatch(numOfTasks); for (int i = 0; i < numOfTasks; i++) { - tasks.put(randomInt(1024), new ClusterStateTaskListener() { + while (null != tasks.put(randomInt(1024), new ClusterStateTaskListener() { @Override public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { latch.countDown(); @@ -392,7 +390,7 @@ public class ClusterServiceTests extends ESTestCase { public void onFailure(String source, Throwable t) { fail(ExceptionsHelper.detailedMessage(t)); } - }); + })) ; } clusterService.submitStateUpdateTasks("test", tasks, ClusterStateTaskConfig.build(Priority.LANGUID), From 14cd8a6794825d3903dd9b54a67261f4f26bf692 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Sat, 18 Jun 2016 18:53:47 +0200 Subject: [PATCH 47/87] Introduce Replication unit tests using real shards (#18930) This commit introduce unit testing infrastructure to test replication operations using real index shards. This is infra is complementary to the full integration tests and unit testing of ReplicationOperation we already have. The new ESIndexLevelReplicationTestCase base makes it easier to test and simulate failure mode that require real shards and but do not need the full blow stack of a complete node. The commit also add a simple "nothing is wrong" test plus a test that checks we don't drop docs during the various stages of recovery. For now, only single doc indexing is supported but this can be easily extended in the future. --- .../replication/ReplicationOperation.java | 18 +- .../ESIndexLevelReplicationTestCase.java | 474 ++++++++++++++++++ .../IndexLevelReplicationTests.java | 31 ++ .../RecoveryDuringReplicationTests.java | 120 +++++ .../org/elasticsearch/test/ESTestCase.java | 7 +- 5 files changed, 640 insertions(+), 10 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java create mode 100644 core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java create mode 100644 core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/ReplicationOperation.java b/core/src/main/java/org/elasticsearch/action/support/replication/ReplicationOperation.java index 8442e705257..0d99c4bfcdf 100644 --- a/core/src/main/java/org/elasticsearch/action/support/replication/ReplicationOperation.java +++ b/core/src/main/java/org/elasticsearch/action/support/replication/ReplicationOperation.java @@ -78,11 +78,11 @@ public class ReplicationOperation< private final List shardReplicaFailures = Collections.synchronizedList(new ArrayList<>()); - ReplicationOperation(Request request, Primary primary, - ActionListener listener, - boolean executeOnReplicas, boolean checkWriteConsistency, - Replicas replicas, - Supplier clusterStateSupplier, ESLogger logger, String opType) { + public ReplicationOperation(Request request, Primary primary, + ActionListener listener, + boolean executeOnReplicas, boolean checkWriteConsistency, + Replicas replicas, + Supplier clusterStateSupplier, ESLogger logger, String opType) { this.checkWriteConsistency = checkWriteConsistency; this.executeOnReplicas = executeOnReplicas; this.replicasProxy = replicas; @@ -94,7 +94,7 @@ public class ReplicationOperation< this.opType = opType; } - void execute() throws Exception { + public void execute() throws Exception { final String writeConsistencyFailure = checkWriteConsistency ? checkWriteConsistency() : null; final ShardRouting primaryRouting = primary.routingEntry(); final ShardId primaryId = primaryRouting.shardId(); @@ -294,7 +294,7 @@ public class ReplicationOperation< } - interface Primary< + public interface Primary< Request extends ReplicationRequest, ReplicaRequest extends ReplicationRequest, PrimaryResultT extends PrimaryResult @@ -322,7 +322,7 @@ public class ReplicationOperation< } - interface Replicas> { + public interface Replicas> { /** * performs the the given request on the specified replica @@ -366,7 +366,7 @@ public class ReplicationOperation< } } - interface PrimaryResult> { + public interface PrimaryResult> { R replicaRequest(); diff --git a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java new file mode 100644 index 00000000000..7ccf0a3e642 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java @@ -0,0 +1,474 @@ +/* + * 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.index.replication; + +import org.apache.lucene.document.Document; +import org.apache.lucene.index.LeafReader; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.store.AlreadyClosedException; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.Bits; +import org.apache.lucene.util.IOUtils; +import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.Version; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.indices.flush.FlushRequest; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.index.TransportIndexAction; +import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.replication.ReplicationOperation; +import org.elasticsearch.action.support.replication.ReplicationResponse; +import org.elasticsearch.action.support.replication.TransportWriteAction; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.cluster.routing.ShardRoutingHelper; +import org.elasticsearch.cluster.routing.ShardRoutingState; +import org.elasticsearch.cluster.routing.TestShardRouting; +import org.elasticsearch.common.collect.Iterators; +import org.elasticsearch.common.compress.CompressedXContent; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.DummyTransportAddress; +import org.elasticsearch.common.unit.ByteSizeUnit; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.MapperTestUtils; +import org.elasticsearch.index.cache.IndexCache; +import org.elasticsearch.index.cache.query.DisabledQueryCache; +import org.elasticsearch.index.engine.Engine; +import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.index.mapper.Uid; +import org.elasticsearch.index.mapper.internal.UidFieldMapper; +import org.elasticsearch.index.shard.IndexEventListener; +import org.elasticsearch.index.shard.IndexShard; +import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.index.shard.ShardPath; +import org.elasticsearch.index.similarity.SimilarityService; +import org.elasticsearch.index.store.DirectoryService; +import org.elasticsearch.index.store.Store; +import org.elasticsearch.indices.recovery.RecoveryFailedException; +import org.elasticsearch.indices.recovery.RecoverySourceHandler; +import org.elasticsearch.indices.recovery.RecoveryState; +import org.elasticsearch.indices.recovery.RecoveryTarget; +import org.elasticsearch.indices.recovery.RecoveryTargetService; +import org.elasticsearch.indices.recovery.StartRecoveryRequest; +import org.elasticsearch.test.DummyShardLock; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.junit.annotations.TestLogging; +import org.elasticsearch.threadpool.TestThreadPool; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportResponse; +import org.junit.After; +import org.junit.Before; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; + +public class ESIndexLevelReplicationTestCase extends ESTestCase { + + private ThreadPool threadPool; + final private Index index = new Index("test", "uuid"); + final private ShardId shardId = new ShardId(index, 0); + final private Map indexMapping = Collections.singletonMap("type", "{ \"type\": {} }"); + protected final static RecoveryTargetService.RecoveryListener recoveryListener = new RecoveryTargetService.RecoveryListener() { + @Override + public void onRecoveryDone(RecoveryState state) { + + } + + @Override + public void onRecoveryFailure(RecoveryState state, RecoveryFailedException e, boolean sendShardFailure) { + fail(ExceptionsHelper.detailedMessage(e)); + } + }; + + + @TestLogging("index.shard:TRACE,index.replication:TRACE,indices.recovery:TRACE") + public void testIndexingDuringFileRecovery() throws Exception { + try (ReplicationGroup shards = createGroup(randomInt(1))) { + shards.startAll(); + int docs = shards.indexDocs(randomInt(50)); + shards.flush(); + IndexShard replica = shards.addReplica(); + final CountDownLatch recoveryBlocked = new CountDownLatch(1); + final CountDownLatch releaseRecovery = new CountDownLatch(1); + final Future recoveryFuture = shards.asyncRecoverReplica(replica, new BiFunction() { + @Override + public RecoveryTarget apply(IndexShard indexShard, DiscoveryNode node) { + return new RecoveryTarget(indexShard, node, recoveryListener) { + @Override + public void renameAllTempFiles() throws IOException { + super.renameAllTempFiles(); + recoveryBlocked.countDown(); + try { + releaseRecovery.await(); + } catch (InterruptedException e) { + throw new IOException("terminated by interrupt", e); + } + } + }; + } + }); + + recoveryBlocked.await(); + docs += shards.indexDocs(randomInt(20)); + releaseRecovery.countDown(); + recoveryFuture.get(); + + shards.assertAllEqual(docs); + } + } + + + @Before + public void setup() { + threadPool = new TestThreadPool(getClass().getName()); + } + + @After + public void destroy() { + ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS); + } + + private Store createStore(IndexSettings indexSettings, ShardPath shardPath) throws IOException { + final ShardId shardId = shardPath.getShardId(); + final DirectoryService directoryService = new DirectoryService(shardId, indexSettings) { + @Override + public Directory newDirectory() throws IOException { + return newFSDirectory(shardPath.resolveIndex()); + } + + @Override + public long throttleTimeInNanos() { + return 0; + } + }; + return new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId)); + } + + protected ReplicationGroup createGroup(int replicas) throws IOException { + final Path homePath = createTempDir(); + Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicas) + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .build(); + IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).primaryTerm(0, 1).build(); + return new ReplicationGroup(metaData, homePath); + } + + private DiscoveryNode getDiscoveryNode(String id) { + return new DiscoveryNode(id, id, DummyTransportAddress.INSTANCE, Collections.emptyMap(), + Collections.singleton(DiscoveryNode.Role.DATA), Version.CURRENT); + } + + private IndexShard newShard(boolean primary, DiscoveryNode node, IndexMetaData indexMetaData, Path homePath) throws IOException { + // add node name to settings for propper logging + final Settings nodeSettings = Settings.builder().put("node.name", node.getName()).build(); + final IndexSettings indexSettings = new IndexSettings(indexMetaData, nodeSettings); + ShardRouting shardRouting = TestShardRouting.newShardRouting(shardId, node.getId(), primary, ShardRoutingState.INITIALIZING); + final Path path = Files.createDirectories(homePath.resolve(node.getId())); + final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(path); + ShardPath shardPath = new ShardPath(false, nodePath.resolve(shardId), nodePath.resolve(shardId), shardId); + Store store = createStore(indexSettings, shardPath); + IndexCache indexCache = new IndexCache(indexSettings, new DisabledQueryCache(indexSettings), null); + MapperService mapperService = MapperTestUtils.newMapperService(homePath, indexSettings.getSettings()); + for (Map.Entry type : indexMapping.entrySet()) { + mapperService.merge(type.getKey(), new CompressedXContent(type.getValue()), MapperService.MergeReason.MAPPING_RECOVERY, true); + } + SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap()); + final IndexEventListener indexEventListener = new IndexEventListener() { + }; + final Engine.Warmer warmer = searcher -> { + }; + return new IndexShard(shardRouting, indexSettings, shardPath, store, indexCache, mapperService, similarityService, null, null, + indexEventListener, null, threadPool, BigArrays.NON_RECYCLING_INSTANCE, warmer, Collections.emptyList(), + Collections.emptyList()); + } + + + class ReplicationGroup implements AutoCloseable, Iterable { + private final IndexShard primary; + private final List replicas; + private final IndexMetaData indexMetaData; + private final Path homePath; + private final AtomicInteger replicaId = new AtomicInteger(); + private final AtomicInteger docId = new AtomicInteger(); + boolean closed = false; + + ReplicationGroup(final IndexMetaData indexMetaData, Path homePath) throws IOException { + primary = newShard(true, getDiscoveryNode("s0"), indexMetaData, homePath); + replicas = new ArrayList<>(); + this.indexMetaData = indexMetaData; + this.homePath = homePath; + for (int i = 0; i < indexMetaData.getNumberOfReplicas(); i++) { + addReplica(); + } + + } + + public int indexDocs(final int numOfDoc) throws Exception { + for (int doc = 0; doc < numOfDoc; doc++) { + final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", Integer.toString(docId.incrementAndGet())) + .source("{}"); + final IndexResponse response = index(indexRequest); + assertThat(response.isCreated(), equalTo(true)); + } + return numOfDoc; + } + + public IndexResponse index(IndexRequest indexRequest) throws Exception { + PlainActionFuture listener = new PlainActionFuture<>(); + IndexingOp op = new IndexingOp(indexRequest, listener, this); + op.execute(); + return listener.get().finalResponse; + } + + public synchronized void startAll() throws IOException { + final DiscoveryNode pNode = getDiscoveryNode(primary.routingEntry().currentNodeId()); + primary.markAsRecovering("store", new RecoveryState(primary.shardId(), true, RecoveryState.Type.STORE, pNode, pNode)); + primary.recoverFromStore(); + primary.updateRoutingEntry(ShardRoutingHelper.moveToStarted(primary.routingEntry())); + for (IndexShard replicaShard : replicas) { + recoverReplica(replicaShard, (replica, sourceNode) -> new RecoveryTarget(replica, sourceNode, recoveryListener)); + } + } + + public synchronized IndexShard addReplica() throws IOException { + final IndexShard replica = newShard(false, getDiscoveryNode("s" + replicaId.incrementAndGet()), indexMetaData, homePath); + replicas.add(replica); + return replica; + } + + public void recoverReplica(IndexShard replica, BiFunction targetSupplier) + throws IOException { + final DiscoveryNode pNode; + synchronized (this) { + pNode = getDiscoveryNode(primary.routingEntry().currentNodeId()); + } + final DiscoveryNode rNode = getDiscoveryNode(replica.routingEntry().currentNodeId()); + replica.markAsRecovering("remote", new RecoveryState(replica.shardId(), false, RecoveryState.Type.REPLICA, pNode, rNode)); + replica.prepareForIndexRecovery(); + RecoveryTarget recoveryTarget = targetSupplier.apply(replica, pNode); + StartRecoveryRequest request = new StartRecoveryRequest(replica.shardId(), pNode, rNode, + replica.store().getMetadataOrEmpty(), RecoveryState.Type.REPLICA, 0); + RecoverySourceHandler recovery = new RecoverySourceHandler(primary, recoveryTarget, request, (int) ByteSizeUnit.MB.toKB(1), + logger); + recovery.recoverToTarget(); + recoveryTarget.markAsDone(); + replica.updateRoutingEntry(ShardRoutingHelper.moveToStarted(replica.routingEntry())); + } + + public Future asyncRecoverReplica(IndexShard replica, BiFunction targetSupplier) + throws IOException { + FutureTask task = new FutureTask<>(() -> { + recoverReplica(replica, targetSupplier); + return null; + }); + threadPool.generic().execute(task); + return task; + } + + public synchronized void assertAllEqual(int expectedCount) throws IOException { + Set primaryIds = getShardDocUIDs(primary); + assertThat(primaryIds.size(), equalTo(expectedCount)); + for (IndexShard replica : replicas) { + Set replicaIds = getShardDocUIDs(replica); + Set temp = new HashSet<>(primaryIds); + temp.removeAll(replicaIds); + assertThat(replica.routingEntry() + " is missing docs", temp, empty()); + temp = new HashSet<>(replicaIds); + temp.removeAll(primaryIds); + assertThat(replica.routingEntry() + " has extra docs", temp, empty()); + } + } + + private Set getShardDocUIDs(final IndexShard shard) throws IOException { + shard.refresh("get_uids"); + try (Engine.Searcher searcher = shard.acquireSearcher("test")) { + Set ids = new HashSet<>(); + for (LeafReaderContext leafContext : searcher.reader().leaves()) { + LeafReader reader = leafContext.reader(); + Bits liveDocs = reader.getLiveDocs(); + for (int i = 0; i < reader.maxDoc(); i++) { + if (liveDocs == null || liveDocs.get(i)) { + Document uuid = reader.document(i, Collections.singleton(UidFieldMapper.NAME)); + ids.add(Uid.createUid(uuid.get(UidFieldMapper.NAME))); + } + } + } + return ids; + } + } + + public synchronized void refresh(String source) { + for (IndexShard shard : this) { + shard.refresh(source); + } + } + + public synchronized void flush() { + final FlushRequest request = new FlushRequest(); + for (IndexShard shard : this) { + shard.flush(request); + } + } + + public synchronized List shardRoutings() { + return StreamSupport.stream(this.spliterator(), false).map(IndexShard::routingEntry).collect(Collectors.toList()); + } + + @Override + public synchronized void close() throws Exception { + if (closed == false) { + closed = true; + for (IndexShard shard : this) { + shard.close("eol", false); + IOUtils.close(shard.store()); + } + } else { + throw new AlreadyClosedException("too bad"); + } + } + + @Override + public Iterator iterator() { + return Iterators.concat(replicas.iterator(), Collections.singleton(primary).iterator()); + } + } + + class IndexingOp extends ReplicationOperation { + + private final ReplicationGroup replicationGroup; + + public IndexingOp(IndexRequest request, ActionListener listener, ReplicationGroup replicationGroup) { + super(request, new PrimaryRef(replicationGroup), listener, true, false, new ReplicasRef(replicationGroup), + () -> null, logger, "indexing"); + this.replicationGroup = replicationGroup; + request.process(null, true, request.index()); + } + + @Override + protected List getShards(ShardId shardId, ClusterState state) { + return replicationGroup.shardRoutings(); + } + + } + + private static class PrimaryRef implements ReplicationOperation.Primary { + final IndexShard primary; + + private PrimaryRef(ReplicationGroup replicationGroup) { + this.primary = replicationGroup.primary; + } + + @Override + public ShardRouting routingEntry() { + return primary.routingEntry(); + } + + @Override + public void failShard(String message, Throwable throwable) { + throw new UnsupportedOperationException(); + } + + @Override + public IndexingResult perform(IndexRequest request) throws Exception { + TransportWriteAction.WriteResult result = TransportIndexAction.executeIndexRequestOnPrimary(request, primary, + null); + request.primaryTerm(primary.getPrimaryTerm()); + return new IndexingResult(request, result.getResponse()); + } + + } + + private static class ReplicasRef implements ReplicationOperation.Replicas { + private final ReplicationGroup replicationGroup; + + private ReplicasRef(ReplicationGroup replicationGroup) { + this.replicationGroup = replicationGroup; + } + + @Override + public void performOn(ShardRouting replicaRouting, IndexRequest request, ActionListener listener) { + try { + IndexShard replica = replicationGroup.replicas.stream() + .filter(s -> replicaRouting.isSameAllocation(s.routingEntry())).findFirst().get(); + TransportIndexAction.executeIndexRequestOnReplica(request, replica); + listener.onResponse(TransportResponse.Empty.INSTANCE); + } catch (Throwable t) { + listener.onFailure(t); + } + } + + @Override + public void failShard(ShardRouting replica, ShardRouting primary, String message, Throwable throwable, Runnable onSuccess, Consumer onPrimaryDemoted, Consumer onIgnoredFailure) { + throw new UnsupportedOperationException(); + } + } + + + private static class IndexingResult implements ReplicationOperation.PrimaryResult { + final IndexRequest replicaRequest; + final IndexResponse finalResponse; + + public IndexingResult(IndexRequest replicaRequest, IndexResponse finalResponse) { + this.replicaRequest = replicaRequest; + this.finalResponse = finalResponse; + } + + @Override + public IndexRequest replicaRequest() { + return replicaRequest; + } + + @Override + public void setShardInfo(ReplicationResponse.ShardInfo shardInfo) { + finalResponse.setShardInfo(shardInfo); + } + + public void respond(ActionListener listener) { + listener.onResponse(finalResponse); + } + } + +} diff --git a/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java b/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java new file mode 100644 index 00000000000..c6d7878406a --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java @@ -0,0 +1,31 @@ +/* + * 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.index.replication; + +public class IndexLevelReplicationTests extends ESIndexLevelReplicationTestCase { + + public void testSimpleReplication() throws Exception { + try (ReplicationGroup shards = createGroup(randomInt(2))) { + shards.startAll(); + final int docCount = randomInt(50); + shards.indexDocs(docCount); + shards.assertAllEqual(docCount); + } + } +} diff --git a/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java b/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java new file mode 100644 index 00000000000..815884edf51 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java @@ -0,0 +1,120 @@ +/* + * 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.index.replication; + +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.index.shard.IndexShard; +import org.elasticsearch.index.store.Store; +import org.elasticsearch.index.translog.Translog; +import org.elasticsearch.indices.recovery.RecoveryState; +import org.elasticsearch.indices.recovery.RecoveryTarget; +import org.elasticsearch.indices.recovery.RecoveryTargetService; + +import java.io.IOException; +import java.util.EnumSet; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; + +public class RecoveryDuringReplicationTests extends ESIndexLevelReplicationTestCase { + + public void testIndexingDuringFileRecovery() throws Exception { + try (ReplicationGroup shards = createGroup(randomInt(1))) { + shards.startAll(); + int docs = shards.indexDocs(randomInt(50)); + shards.flush(); + IndexShard replica = shards.addReplica(); + final CountDownLatch recoveryBlocked = new CountDownLatch(1); + final CountDownLatch releaseRecovery = new CountDownLatch(1); + final RecoveryState.Stage blockOnStage = randomFrom(BlockingTarget.SUPPORTED_STAGES); + final Future recoveryFuture = shards.asyncRecoverReplica(replica, (indexShard, node) -> + new BlockingTarget(blockOnStage, recoveryBlocked, releaseRecovery, indexShard, node, recoveryListener, logger)); + + recoveryBlocked.await(); + docs += shards.indexDocs(randomInt(20)); + releaseRecovery.countDown(); + recoveryFuture.get(); + + shards.assertAllEqual(docs); + } + } + + private static class BlockingTarget extends RecoveryTarget { + private final CountDownLatch recoveryBlocked; + private final CountDownLatch releaseRecovery; + private final RecoveryState.Stage stageToBlock; + public static final EnumSet SUPPORTED_STAGES = + EnumSet.of(RecoveryState.Stage.INDEX, RecoveryState.Stage.TRANSLOG, RecoveryState.Stage.FINALIZE); + private final ESLogger logger; + + BlockingTarget(RecoveryState.Stage stageToBlock, CountDownLatch recoveryBlocked, CountDownLatch releaseRecovery, IndexShard shard, + DiscoveryNode sourceNode, RecoveryTargetService.RecoveryListener listener, ESLogger logger) { + super(shard, sourceNode, listener); + this.recoveryBlocked = recoveryBlocked; + this.releaseRecovery = releaseRecovery; + this.stageToBlock = stageToBlock; + this.logger = logger; + if (SUPPORTED_STAGES.contains(stageToBlock) == false) { + throw new UnsupportedOperationException(stageToBlock + " is not supported"); + } + } + + private boolean hasBlocked() { + return recoveryBlocked.getCount() == 0; + } + + private void blockIfNeeded(RecoveryState.Stage currentStage) { + if (currentStage == stageToBlock) { + logger.info("--> blocking recovery on stage [{}]", currentStage); + recoveryBlocked.countDown(); + try { + releaseRecovery.await(); + logger.info("--> recovery continues from stage [{}]", currentStage); + } catch (InterruptedException e) { + throw new RuntimeException("blockage released"); + } + } + } + + @Override + public void indexTranslogOperations(List operations, int totalTranslogOps) { + if (hasBlocked() == false) { + blockIfNeeded(RecoveryState.Stage.TRANSLOG); + } + super.indexTranslogOperations(operations, totalTranslogOps); + } + + @Override + public void cleanFiles(int totalTranslogOps, Store.MetadataSnapshot sourceMetaData) throws IOException { + blockIfNeeded(RecoveryState.Stage.INDEX); + super.cleanFiles(totalTranslogOps, sourceMetaData); + } + + @Override + public void finalizeRecovery() { + if (hasBlocked() == false) { + // it maybe that not ops have been transferred, block now + blockIfNeeded(RecoveryState.Stage.TRANSLOG); + } + blockIfNeeded(RecoveryState.Stage.FINALIZE); + super.finalizeRecovery(); + } + } +} diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index e0ae77d3f56..172c99592df 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -36,7 +36,6 @@ import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TimeUnits; import org.elasticsearch.Version; import org.elasticsearch.bootstrap.BootstrapForTesting; -import org.elasticsearch.common.util.MockPageCacheRecycler; import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.bytes.BytesReference; @@ -47,6 +46,7 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.util.MockBigArrays; +import org.elasticsearch.common.util.MockPageCacheRecycler; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -334,6 +334,11 @@ public abstract class ESTestCase extends LuceneTestCase { return RandomPicks.randomFrom(random(), list); } + /** Pick a random object from the given collection. */ + public static T randomFrom(Collection collection) { + return RandomPicks.randomFrom(random(), collection); + } + public static String randomAsciiOfLengthBetween(int minCodeUnits, int maxCodeUnits) { return RandomizedTest.randomAsciiOfLengthBetween(minCodeUnits, maxCodeUnits); } From 61b7f49ed25b483a10dff5a56f7cbb992342e200 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Sat, 18 Jun 2016 19:13:50 +0200 Subject: [PATCH 48/87] ESIndexLevelReplicationTestCase.java fix line lengths --- .../index/replication/ESIndexLevelReplicationTestCase.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java index 7ccf0a3e642..924469ca6cb 100644 --- a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java @@ -132,7 +132,8 @@ public class ESIndexLevelReplicationTestCase extends ESTestCase { IndexShard replica = shards.addReplica(); final CountDownLatch recoveryBlocked = new CountDownLatch(1); final CountDownLatch releaseRecovery = new CountDownLatch(1); - final Future recoveryFuture = shards.asyncRecoverReplica(replica, new BiFunction() { + final Future recoveryFuture = shards.asyncRecoverReplica(replica, + new BiFunction() { @Override public RecoveryTarget apply(IndexShard indexShard, DiscoveryNode node) { return new RecoveryTarget(indexShard, node, recoveryListener) { @@ -441,7 +442,8 @@ public class ESIndexLevelReplicationTestCase extends ESTestCase { } @Override - public void failShard(ShardRouting replica, ShardRouting primary, String message, Throwable throwable, Runnable onSuccess, Consumer onPrimaryDemoted, Consumer onIgnoredFailure) { + public void failShard(ShardRouting replica, ShardRouting primary, String message, Throwable throwable, Runnable onSuccess, + Consumer onPrimaryDemoted, Consumer onIgnoredFailure) { throw new UnsupportedOperationException(); } } From 8f96dd53aa5e220daad63c85ecfad7f28db274d8 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Sat, 18 Jun 2016 19:39:37 +0200 Subject: [PATCH 49/87] mark ESIndexLevelReplicationTestCase as abstract so it won't fail naming conventions --- .../index/replication/ESIndexLevelReplicationTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java index 924469ca6cb..edf5a0d28f2 100644 --- a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java @@ -104,7 +104,7 @@ import java.util.stream.StreamSupport; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; -public class ESIndexLevelReplicationTestCase extends ESTestCase { +public abstract class ESIndexLevelReplicationTestCase extends ESTestCase { private ThreadPool threadPool; final private Index index = new Index("test", "uuid"); From 8d9fa7e0b56635c084dc8e443f446d8f34d60f59 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sun, 19 Jun 2016 03:19:45 -0400 Subject: [PATCH 50/87] Fix explicit casts and improve tests. --- .../painless/CompilerSettings.java | 26 ++ .../java/org/elasticsearch/painless/Def.java | 3 +- .../elasticsearch/painless/DefBootstrap.java | 72 +++-- .../org/elasticsearch/painless/DefMath.java | 121 +++---- .../elasticsearch/painless/MethodWriter.java | 49 +-- .../painless/PainlessScriptEngineService.java | 6 + .../painless/WriterConstants.java | 7 +- .../elasticsearch/painless/antlr/Walker.java | 2 +- .../elasticsearch/painless/node/EBinary.java | 11 +- .../painless/node/ECapturingFunctionRef.java | 5 +- .../elasticsearch/painless/node/EChain.java | 8 +- .../elasticsearch/painless/node/EComp.java | 15 +- .../elasticsearch/painless/node/EUnary.java | 16 +- .../painless/node/LDefArray.java | 10 +- .../elasticsearch/painless/node/LDefCall.java | 20 +- .../painless/node/LDefField.java | 10 +- .../elasticsearch/painless/node/SEach.java | 5 +- .../painless/node/SFunction.java | 5 +- .../elasticsearch/painless/node/SSource.java | 17 +- .../org/elasticsearch/painless/CastTests.java | 298 ++++++++++++++++++ .../painless/DefBootstrapTests.java | 10 + .../painless/DefOptimizationTests.java | 12 +- .../painless/ScriptTestCase.java | 1 + 23 files changed, 572 insertions(+), 157 deletions(-) create mode 100644 modules/lang-painless/src/test/java/org/elasticsearch/painless/CastTests.java diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/CompilerSettings.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/CompilerSettings.java index 79b75b32b98..94d7a1305d6 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/CompilerSettings.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/CompilerSettings.java @@ -33,6 +33,11 @@ public final class CompilerSettings { * Constant to be used for enabling additional internal compilation checks (slower). */ public static final String PICKY = "picky"; + + /** + * For testing: do not use. + */ + public static final String INITIAL_CALL_SITE_DEPTH = "initialCallSiteDepth"; /** * The maximum number of statements allowed to be run in a loop. @@ -44,6 +49,11 @@ public final class CompilerSettings { * makes things slower too, it is only for debugging. */ private boolean picky = false; + + /** + * For testing. Do not use. + */ + private int initialCallSiteDepth = 0; /** * Returns the value for the cumulative total number of statements that can be made in all loops @@ -78,4 +88,20 @@ public final class CompilerSettings { public void setPicky(boolean picky) { this.picky = picky; } + + /** + * Returns initial call site depth. This means we pretend we've already seen N different types, + * to better exercise fallback code in tests. + */ + public int getInitialCallSiteDepth() { + return initialCallSiteDepth; + } + + /** + * For testing megamorphic fallbacks. Do not use. + * @see #getInitialCallSiteDepth() + */ + public void setInitialCallSiteDepth(int depth) { + this.initialCallSiteDepth = depth; + } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java index a4033255b77..7c7ff5f7f5a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java @@ -279,7 +279,8 @@ public final class Def { MethodType nestedType = MethodType.methodType(interfaceType.clazz, captures); CallSite nested = DefBootstrap.bootstrap(lookup, call, - nestedType, + nestedType, + 0, DefBootstrap.REFERENCE, interfaceType.name); filter = nested.dynamicInvoker(); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java index a60985eec67..fa533eff213 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java @@ -27,6 +27,7 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.MethodType; import java.lang.invoke.MutableCallSite; +import java.lang.invoke.WrongMethodTypeException; /** * Painless invokedynamic bootstrap for the call site. @@ -80,9 +81,18 @@ public final class DefBootstrap { /** * static bootstrap parameter indicating the binary operator is part of compound assignment (e.g. +=). - * + *

+ * may require {@link MethodHandles#explicitCastArguments}, or a dynamic cast + * to cast back to the receiver's type, depending on types seen. */ public static final int OPERATOR_COMPOUND_ASSIGNMENT = 1 << 1; + + /** + * static bootstrap parameter indicating an explicit cast to the return type. + *

+ * may require {@link MethodHandles#explicitCastArguments}, depending on types seen. + */ + public static final int OPERATOR_EXPLICIT_CAST = 1 << 2; /** * CallSite that implements the polymorphic inlining cache (PIC). @@ -97,7 +107,7 @@ public final class DefBootstrap { private final Object[] args; int depth; // pkg-protected for testing - PIC(Lookup lookup, String name, MethodType type, int flavor, Object[] args) { + PIC(Lookup lookup, String name, MethodType type, int initialDepth, int flavor, Object[] args) { super(type); if (type.parameterType(0) != Object.class) { throw new BootstrapMethodError("The receiver type (1st arg) of invokedynamic descriptor must be Object."); @@ -106,6 +116,7 @@ public final class DefBootstrap { this.name = name; this.flavor = flavor; this.args = args; + this.depth = initialDepth; MethodHandle fallback = FALLBACK.bindTo(this) .asCollector(Object[].class, type.parameterCount()) @@ -226,11 +237,14 @@ public final class DefBootstrap { private final int flavor; private final int flags; - MIC(String name, MethodType type, int flavor, int flags) { + MIC(String name, MethodType type, int initialDepth, int flavor, int flags) { super(type); this.name = name; this.flavor = flavor; this.flags = flags; + if (initialDepth > 0) { + initialized = true; + } MethodHandle fallback = FALLBACK.bindTo(this) .asCollector(Object[].class, type.parameterCount()) @@ -248,7 +262,9 @@ public final class DefBootstrap { case SHIFT_OPERATOR: // shifts are treated as unary, as java allows long arguments without a cast (but bits are ignored) MethodHandle unary = DefMath.lookupUnary(args[0].getClass(), name); - if ((flags & OPERATOR_COMPOUND_ASSIGNMENT) != 0) { + if ((flags & OPERATOR_EXPLICIT_CAST) != 0) { + unary = DefMath.cast(type().returnType(), unary); + } else if ((flags & OPERATOR_COMPOUND_ASSIGNMENT) != 0) { unary = DefMath.cast(args[0].getClass(), unary); } return unary; @@ -257,7 +273,9 @@ public final class DefBootstrap { return lookupGeneric(); // can handle nulls, casts if supported } else { MethodHandle binary = DefMath.lookupBinary(args[0].getClass(), args[1].getClass(), name); - if ((flags & OPERATOR_COMPOUND_ASSIGNMENT) != 0) { + if ((flags & OPERATOR_EXPLICIT_CAST) != 0) { + binary = DefMath.cast(type().returnType(), binary); + } else if ((flags & OPERATOR_COMPOUND_ASSIGNMENT) != 0) { binary = DefMath.cast(args[0].getClass(), binary); } return binary; @@ -267,11 +285,15 @@ public final class DefBootstrap { } private MethodHandle lookupGeneric() { - if ((flags & OPERATOR_COMPOUND_ASSIGNMENT) != 0) { - return DefMath.lookupGenericWithCast(name); - } else { - return DefMath.lookupGeneric(name); + MethodHandle target = DefMath.lookupGeneric(name); + if ((flags & OPERATOR_EXPLICIT_CAST) != 0) { + // static cast to the return type + target = DefMath.dynamicCast(target, type().returnType()); + } else if ((flags & OPERATOR_COMPOUND_ASSIGNMENT) != 0) { + // dynamic cast to the receiver's type + target = DefMath.dynamicCast(target); } + return target; } /** @@ -288,7 +310,15 @@ public final class DefBootstrap { } final MethodType type = type(); - final MethodHandle target = lookup(args).asType(type); + MethodHandle target = lookup(args); + // for math operators: WrongMethodType can be confusing. convert into a ClassCastException if they screw up. + try { + target = target.asType(type); + } catch (WrongMethodTypeException e) { + Exception exc = new ClassCastException("Cannot cast from: " + target.type().returnType() + " to " + type.returnType()); + exc.initCause(e); + throw exc; + } final MethodHandle test; if (flavor == BINARY_OPERATOR || flavor == SHIFT_OPERATOR) { @@ -384,12 +414,16 @@ public final class DefBootstrap { /** * invokeDynamic bootstrap method *

- * In addition to ordinary parameters, we also take a static parameter {@code flavor} which - * tells us what type of dynamic call it is (and which part of whitelist to look at). + * In addition to ordinary parameters, we also take some static parameters: + *

    + *
  • {@code initialDepth}: initial call site depth. this is used to exercise megamorphic fallback. + *
  • {@code flavor}: type of dynamic call it is (and which part of whitelist to look at). + *
  • {@code args}: flavor-specific args. + *
*

* see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokedynamic */ - public static CallSite bootstrap(Lookup lookup, String name, MethodType type, int flavor, Object... args) { + public static CallSite bootstrap(Lookup lookup, String name, MethodType type, int initialDepth, int flavor, Object... args) { // validate arguments switch(flavor) { // "function-call" like things get a polymorphic cache @@ -408,7 +442,7 @@ public final class DefBootstrap { if (args.length != numLambdas + 1) { throw new BootstrapMethodError("Illegal number of parameters: expected " + numLambdas + " references"); } - return new PIC(lookup, name, type, flavor, args); + return new PIC(lookup, name, type, initialDepth, flavor, args); case LOAD: case STORE: case ARRAY_LOAD: @@ -417,7 +451,7 @@ public final class DefBootstrap { if (args.length > 0) { throw new BootstrapMethodError("Illegal static bootstrap parameters for flavor: " + flavor); } - return new PIC(lookup, name, type, flavor, args); + return new PIC(lookup, name, type, initialDepth, flavor, args); case REFERENCE: if (args.length != 1) { throw new BootstrapMethodError("Invalid number of parameters for reference call"); @@ -425,7 +459,7 @@ public final class DefBootstrap { if (args[0] instanceof String == false) { throw new BootstrapMethodError("Illegal parameter for reference call: " + args[0]); } - return new PIC(lookup, name, type, flavor, args); + return new PIC(lookup, name, type, initialDepth, flavor, args); // operators get monomorphic cache, with a generic impl for a fallback case UNARY_OPERATOR: @@ -442,11 +476,11 @@ public final class DefBootstrap { // we just don't need it anywhere else. throw new BootstrapMethodError("This parameter is only supported for BINARY_OPERATORs"); } - if ((flags & OPERATOR_COMPOUND_ASSIGNMENT) != 0 && flavor != BINARY_OPERATOR) { + if ((flags & OPERATOR_COMPOUND_ASSIGNMENT) != 0 && flavor != BINARY_OPERATOR && flavor != SHIFT_OPERATOR) { // we just don't need it anywhere else. - throw new BootstrapMethodError("This parameter is only supported for BINARY_OPERATORs"); + throw new BootstrapMethodError("This parameter is only supported for BINARY/SHIFT_OPERATORs"); } - return new MIC(name, type, flavor, flags); + return new MIC(name, type, initialDepth, flavor, flags); default: throw new BootstrapMethodError("Illegal static bootstrap parameter for flavor: " + flavor); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java index f56256f6cb2..65a26cd3da8 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java @@ -25,6 +25,7 @@ import java.lang.invoke.MethodType; import java.lang.invoke.MethodHandles.Lookup; import java.util.Collections; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @@ -1027,25 +1028,7 @@ public class DefMath { * class if its not a boxed type. */ private static Class unbox(Class clazz) { - if (clazz == Boolean.class) { - return boolean.class; - } else if (clazz == Byte.class) { - return byte.class; - } else if (clazz == Short.class) { - return short.class; - } else if (clazz == Character.class) { - return char.class; - } else if (clazz == Integer.class) { - return int.class; - } else if (clazz == Long.class) { - return long.class; - } else if (clazz == Float.class) { - return float.class; - } else if (clazz == Double.class) { - return double.class; - } else { - return clazz; - } + return MethodType.methodType(clazz).unwrap().returnType(); } /** Unary promotion. All Objects are promoted to Object. */ @@ -1146,40 +1129,50 @@ public class DefMath { public static MethodHandle lookupGeneric(String name) { return TYPE_OP_MAPPING.get(Object.class).get(name); } - - + /** * Slow dynamic cast: casts {@code returnValue} to the runtime type of {@code lhs} * based upon inspection. If {@code lhs} is null, no cast takes place. * This is used for the generic fallback case of compound assignment. */ - static Object dynamicCast(Object returnValue, Object lhs) { + static Object dynamicReceiverCast(Object returnValue, Object lhs) { if (lhs != null) { - Class c = lhs.getClass(); - if (c == returnValue.getClass()) { - return returnValue; - } - if (c == Integer.class) { - return getNumber(returnValue).intValue(); - } else if (c == Long.class) { - return getNumber(returnValue).longValue(); - } else if (c == Double.class) { - return getNumber(returnValue).doubleValue(); - } else if (c == Float.class) { - return getNumber(returnValue).floatValue(); - } else if (c == Short.class) { - return getNumber(returnValue).shortValue(); - } else if (c == Byte.class) { - return getNumber(returnValue).byteValue(); - } else if (c == Character.class) { - return (char) getNumber(returnValue).intValue(); - } - return lhs.getClass().cast(returnValue); + return dynamicCast(lhs.getClass(), returnValue); } else { return returnValue; } } + /** + * Slow dynamic cast: casts {@code value} to an instance of {@code clazz} + * based upon inspection. If {@code lhs} is null, no cast takes place. + */ + static Object dynamicCast(Class clazz, Object value) { + if (value != null) { + if (clazz == value.getClass()) { + return value; + } + if (clazz == Integer.class) { + return getNumber(value).intValue(); + } else if (clazz == Long.class) { + return getNumber(value).longValue(); + } else if (clazz == Double.class) { + return getNumber(value).doubleValue(); + } else if (clazz == Float.class) { + return getNumber(value).floatValue(); + } else if (clazz == Short.class) { + return getNumber(value).shortValue(); + } else if (clazz == Byte.class) { + return getNumber(value).byteValue(); + } else if (clazz == Character.class) { + return (char) getNumber(value).intValue(); + } + return clazz.cast(value); + } else { + return value; + } + } + /** Slowly returns a Number for o. Just for supporting dynamicCast */ static Number getNumber(Object o) { if (o instanceof Number) { @@ -1192,28 +1185,40 @@ public class DefMath { } private static final MethodHandle DYNAMIC_CAST; + private static final MethodHandle DYNAMIC_RECEIVER_CAST; static { final Lookup lookup = MethodHandles.lookup(); try { DYNAMIC_CAST = lookup.findStatic(lookup.lookupClass(), - "dynamicCast", - MethodType.methodType(Object.class, Object.class, Object.class)); + "dynamicCast", + MethodType.methodType(Object.class, Class.class, Object.class)); + DYNAMIC_RECEIVER_CAST = lookup.findStatic(lookup.lookupClass(), + "dynamicReceiverCast", + MethodType.methodType(Object.class, Object.class, Object.class)); } catch (ReflectiveOperationException e) { throw new AssertionError(e); } } /** Looks up generic method, with a dynamic cast to the receiver's type. (compound assignment) */ - public static MethodHandle lookupGenericWithCast(String name) { - MethodHandle generic = lookupGeneric(name); - // adapt dynamic cast to the generic method - MethodHandle cast = DYNAMIC_CAST.asType(MethodType.methodType(generic.type().returnType(), - generic.type().returnType(), - generic.type().parameterType(0))); + public static MethodHandle dynamicCast(MethodHandle target) { + // adapt dynamic receiver cast to the generic method + MethodHandle cast = DYNAMIC_RECEIVER_CAST.asType(MethodType.methodType(target.type().returnType(), + target.type().returnType(), + target.type().parameterType(0))); // drop the RHS parameter - cast = MethodHandles.dropArguments(cast, 2, generic.type().parameterType(1)); + cast = MethodHandles.dropArguments(cast, 2, target.type().parameterType(1)); // combine: f(x,y) -> g(f(x,y), x, y); - return MethodHandles.foldArguments(cast, generic); + return MethodHandles.foldArguments(cast, target); + } + + /** Looks up generic method, with a dynamic cast to the specified type. (explicit assignment) */ + public static MethodHandle dynamicCast(MethodHandle target, Class desired) { + // adapt dynamic cast to the generic method + desired = MethodType.methodType(desired).wrap().returnType(); + // bind to the boxed type + MethodHandle cast = DYNAMIC_CAST.bindTo(desired); + return MethodHandles.filterReturnValue(target, cast); } /** Forces a cast to class A for target (only if types differ) */ @@ -1221,12 +1226,18 @@ public class DefMath { MethodType newType = MethodType.methodType(classA).unwrap(); MethodType targetType = MethodType.methodType(target.type().returnType()).unwrap(); + // don't do a conversion if types are the same. explicitCastArguments has this opto, + // but we do it explicitly, to make the boolean check simpler if (newType.returnType() == targetType.returnType()) { - return target; // no conversion + return target; } - // this is safe for our uses of it here only, because we change just the return value, - // the original method itself does all the type checks correctly. + // we don't allow the to/from boolean conversions of explicitCastArguments + if (newType.returnType() == boolean.class || targetType.returnType() == boolean.class) { + throw new ClassCastException("Cannot cast " + targetType.returnType() + " to " + newType.returnType()); + } + + // null return values are not possible for our arguments. return MethodHandles.explicitCastArguments(target, target.type().changeReturnType(newType.returnType())); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java index 6241b5b4207..97686655a97 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java @@ -30,6 +30,7 @@ import org.objectweb.asm.commons.Method; import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Arrays; import java.util.BitSet; import java.util.Deque; import java.util.List; @@ -78,15 +79,17 @@ import static org.elasticsearch.painless.WriterConstants.UTILITY_TYPE; */ public final class MethodWriter extends GeneratorAdapter { private final BitSet statements; + private final CompilerSettings settings; private final Deque> stringConcatArgs = (INDY_STRING_CONCAT_BOOTSTRAP_HANDLE == null) ? null : new ArrayDeque<>(); - public MethodWriter(int access, Method method, ClassVisitor cw, BitSet statements) { + public MethodWriter(int access, Method method, ClassVisitor cw, BitSet statements, CompilerSettings settings) { super(Opcodes.ASM5, cw.visitMethod(access, method.getName(), method.getDescriptor(), null, null), access, method.getName(), method.getDescriptor()); this.statements = statements; + this.settings = settings; } /** @@ -269,23 +272,18 @@ public final class MethodWriter extends GeneratorAdapter { /** Writes a dynamic binary instruction: returnType, lhs, and rhs can be different */ public void writeDynamicBinaryInstruction(Location location, Type returnType, Type lhs, Type rhs, - Operation operation, boolean compoundAssignment) { + Operation operation, int flags) { org.objectweb.asm.Type methodType = org.objectweb.asm.Type.getMethodType(returnType.type, lhs.type, rhs.type); - String descriptor = methodType.getDescriptor(); - int flags = 0; - if (compoundAssignment) { - flags |= DefBootstrap.OPERATOR_COMPOUND_ASSIGNMENT; - } switch (operation) { case MUL: - invokeDynamic("mul", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, flags); + invokeDefCall("mul", methodType, DefBootstrap.BINARY_OPERATOR, flags); break; case DIV: - invokeDynamic("div", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, flags); + invokeDefCall("div", methodType, DefBootstrap.BINARY_OPERATOR, flags); break; case REM: - invokeDynamic("rem", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, flags); + invokeDefCall("rem", methodType, DefBootstrap.BINARY_OPERATOR, flags); break; case ADD: // if either side is primitive, then the + operator should always throw NPE on null, @@ -295,28 +293,28 @@ public final class MethodWriter extends GeneratorAdapter { if (!hasPrimitiveArg) { flags |= DefBootstrap.OPERATOR_ALLOWS_NULL; } - invokeDynamic("add", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, flags); + invokeDefCall("add", methodType, DefBootstrap.BINARY_OPERATOR, flags); break; case SUB: - invokeDynamic("sub", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, flags); + invokeDefCall("sub", methodType, DefBootstrap.BINARY_OPERATOR, flags); break; case LSH: - invokeDynamic("lsh", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.SHIFT_OPERATOR, flags); + invokeDefCall("lsh", methodType, DefBootstrap.SHIFT_OPERATOR, flags); break; case USH: - invokeDynamic("ush", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.SHIFT_OPERATOR, flags); + invokeDefCall("ush", methodType, DefBootstrap.SHIFT_OPERATOR, flags); break; case RSH: - invokeDynamic("rsh", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.SHIFT_OPERATOR, flags); + invokeDefCall("rsh", methodType, DefBootstrap.SHIFT_OPERATOR, flags); break; case BWAND: - invokeDynamic("and", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, flags); + invokeDefCall("and", methodType, DefBootstrap.BINARY_OPERATOR, flags); break; case XOR: - invokeDynamic("xor", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, flags); + invokeDefCall("xor", methodType, DefBootstrap.BINARY_OPERATOR, flags); break; case BWOR: - invokeDynamic("or", descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, flags); + invokeDefCall("or", methodType, DefBootstrap.BINARY_OPERATOR, flags); break; default: throw location.createError(new IllegalStateException("Illegal tree structure.")); @@ -391,4 +389,19 @@ public final class MethodWriter extends GeneratorAdapter { public void visitEnd() { throw new AssertionError("Should never call this method on MethodWriter, use endMethod() instead"); } + + /** + * Writes a dynamic call for a def method. + * @param name method name + * @param methodType callsite signature + * @param flavor type of call + * @param params flavor-specific parameters + */ + public void invokeDefCall(String name, org.objectweb.asm.Type methodType, int flavor, Object... params) { + Object[] args = new Object[params.length + 2]; + args[0] = settings.getInitialCallSiteDepth(); + args[1] = flavor; + System.arraycopy(params, 0, args, 2, params.length); + invokeDynamic(name, methodType.getDescriptor(), DEF_BOOTSTRAP_HANDLE, args); + } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java index bb94785d339..365060fe004 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java @@ -127,6 +127,12 @@ public final class PainlessScriptEngineService extends AbstractComponent impleme if (value != null) { compilerSettings.setPicky(Boolean.parseBoolean(value)); } + + value = copy.remove(CompilerSettings.INITIAL_CALL_SITE_DEPTH); + + if (value != null) { + compilerSettings.setInitialCallSiteDepth(Integer.parseInt(value)); + } if (!copy.isEmpty()) { throw new IllegalArgumentException("Unrecognized compile-time parameter(s): " + copy); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java index 6960e906339..d581ba8518a 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java @@ -85,9 +85,10 @@ public final class WriterConstants { public final static Method MATCHER_FIND = getAsmMethod(boolean.class, "find"); /** dynamic callsite bootstrap signature */ - public final static MethodType DEF_BOOTSTRAP_TYPE = - MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, int.class, Object[].class); - public final static Handle DEF_BOOTSTRAP_HANDLE = + final static MethodType DEF_BOOTSTRAP_TYPE = + MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, + int.class, int.class, Object[].class); + final static Handle DEF_BOOTSTRAP_HANDLE = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(DefBootstrap.class), "bootstrap", DEF_BOOTSTRAP_TYPE.toMethodDescriptorString(), false); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java index b92bd6733c9..a84247afe25 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/Walker.java @@ -241,7 +241,7 @@ public final class Walker extends PainlessParserBaseVisitor { statements.add((AStatement)visit(statement)); } - return new SSource(sourceName, sourceText, debugStream, (MainMethodReserved)reserved.pop(), + return new SSource(settings, sourceName, sourceText, debugStream, (MainMethodReserved)reserved.pop(), location(ctx), functions, globals, statements); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java index 11b77b0441f..87b12284789 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java @@ -20,6 +20,7 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Definition.Sort; @@ -42,6 +43,7 @@ public final class EBinary extends AExpression { Type shiftDistance; // for shifts, the RHS is promoted independently boolean cat = false; + boolean originallyExplicit = false; // record whether there was originally an explicit cast public EBinary(Location location, Operation operation, AExpression left, AExpression right) { super(location); @@ -53,6 +55,7 @@ public final class EBinary extends AExpression { @Override void analyze(Locals locals) { + originallyExplicit = explicit; if (operation == Operation.MUL) { analyzeMul(locals); } else if (operation == Operation.DIV) { @@ -639,7 +642,13 @@ public final class EBinary extends AExpression { right.write(writer, globals); if (promote.sort == Sort.DEF || (shiftDistance != null && shiftDistance.sort == Sort.DEF)) { - writer.writeDynamicBinaryInstruction(location, actual, left.actual, right.actual, operation, false); + // def calls adopt the wanted return value. if there was a narrowing cast, + // we need to flag that so that its done at runtime. + int flags = 0; + if (originallyExplicit) { + flags |= DefBootstrap.OPERATOR_EXPLICIT_CAST; + } + writer.writeDynamicBinaryInstruction(location, actual, left.actual, right.actual, operation, flags); } else { writer.writeBinaryInstruction(location, actual, operation); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java index 333787db962..62ecf63b9b3 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java @@ -30,7 +30,6 @@ import org.elasticsearch.painless.Locals.Variable; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; -import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; import static org.elasticsearch.painless.WriterConstants.LAMBDA_BOOTSTRAP_HANDLE; import java.lang.invoke.LambdaMetafactory; @@ -90,8 +89,8 @@ public class ECapturingFunctionRef extends AExpression implements ILambda { } else if (ref == null) { // typed interface, dynamic implementation writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.getSlot()); - String descriptor = Type.getMethodType(expected.type, captured.type.type).getDescriptor(); - writer.invokeDynamic(call, descriptor, DEF_BOOTSTRAP_HANDLE, DefBootstrap.REFERENCE, expected.name); + Type methodType = Type.getMethodType(expected.type, captured.type.type); + writer.invokeDefCall(call, methodType, DefBootstrap.REFERENCE, expected.name); } else { // typed interface, typed implementation writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.getSlot()); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java index b249cf4511e..aa5bbcaab9d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java @@ -26,6 +26,7 @@ import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.AnalyzerCaster; +import org.elasticsearch.painless.DefBootstrap; import org.elasticsearch.painless.Operation; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; @@ -214,7 +215,10 @@ public final class EChain extends AExpression { expression.expected = expression.actual; } else if (shift) { - if (shiftDistance.sort == Sort.LONG) { + if (promote.sort == Sort.DEF) { + // shifts are promoted independently, but for the def type, we need object. + expression.expected = promote; + } else if (shiftDistance.sort == Sort.LONG) { expression.expected = Definition.INT_TYPE; expression.explicit = true; } else { @@ -353,7 +357,7 @@ public final class EChain extends AExpression { // write the operation instruction for compound assignment if (promote.sort == Sort.DEF) { writer.writeDynamicBinaryInstruction(location, promote, - Definition.DEF_TYPE, Definition.DEF_TYPE, operation, true); + Definition.DEF_TYPE, Definition.DEF_TYPE, operation, DefBootstrap.OPERATOR_COMPOUND_ASSIGNMENT); } else { writer.writeBinaryInstruction(location, promote, operation); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java index 53684a19005..31050f9f6ce 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EComp.java @@ -33,7 +33,6 @@ import org.elasticsearch.painless.MethodWriter; import static org.elasticsearch.painless.WriterConstants.OBJECTS_TYPE; import static org.elasticsearch.painless.WriterConstants.EQUALS; -import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; /** * Represents a comparison expression. @@ -498,8 +497,7 @@ public final class EComp extends AExpression { if (right.isNull) { writer.ifNull(jump); } else if (!left.isNull && (operation == Operation.EQ || operation == Operation.NE)) { - writer.invokeDynamic("eq", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, - DefBootstrap.OPERATOR_ALLOWS_NULL); + writer.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); writejump = false; } else { writer.ifCmp(promotedType.type, MethodWriter.EQ, jump); @@ -508,23 +506,22 @@ public final class EComp extends AExpression { if (right.isNull) { writer.ifNonNull(jump); } else if (!left.isNull && (operation == Operation.EQ || operation == Operation.NE)) { - writer.invokeDynamic("eq", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, - DefBootstrap.OPERATOR_ALLOWS_NULL); + writer.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); writer.ifZCmp(MethodWriter.EQ, jump); } else { writer.ifCmp(promotedType.type, MethodWriter.NE, jump); } } else if (lt) { - writer.invokeDynamic("lt", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, 0); + writer.invokeDefCall("lt", descriptor, DefBootstrap.BINARY_OPERATOR, 0); writejump = false; } else if (lte) { - writer.invokeDynamic("lte", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, 0); + writer.invokeDefCall("lte", descriptor, DefBootstrap.BINARY_OPERATOR, 0); writejump = false; } else if (gt) { - writer.invokeDynamic("gt", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, 0); + writer.invokeDefCall("gt", descriptor, DefBootstrap.BINARY_OPERATOR, 0); writejump = false; } else if (gte) { - writer.invokeDynamic("gte", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.BINARY_OPERATOR, 0); + writer.invokeDefCall("gte", descriptor, DefBootstrap.BINARY_OPERATOR, 0); writejump = false; } else { throw createError(new IllegalStateException("Illegal tree structure.")); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java index f74b91dd5bc..40776811b67 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EUnary.java @@ -31,8 +31,6 @@ import org.elasticsearch.painless.Locals; import org.objectweb.asm.Label; import org.elasticsearch.painless.MethodWriter; -import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; - /** * Represents a unary math expression. */ @@ -41,6 +39,7 @@ public final class EUnary extends AExpression { final Operation operation; AExpression child; Type promote; + boolean originallyExplicit = false; // record whether there was originally an explicit cast public EUnary(Location location, Operation operation, AExpression child) { super(location); @@ -51,6 +50,7 @@ public final class EUnary extends AExpression { @Override void analyze(Locals locals) { + originallyExplicit = explicit; if (operation == Operation.NOT) { analyzeNot(locals); } else if (operation == Operation.BWNOT) { @@ -203,10 +203,16 @@ public final class EUnary extends AExpression { Sort sort = promote.sort; child.write(writer, globals); + // def calls adopt the wanted return value. if there was a narrowing cast, + // we need to flag that so that its done at runtime. + int defFlags = 0; + if (originallyExplicit) { + defFlags |= DefBootstrap.OPERATOR_EXPLICIT_CAST; + } if (operation == Operation.BWNOT) { if (sort == Sort.DEF) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type); - writer.invokeDynamic("not", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.UNARY_OPERATOR, 0); + writer.invokeDefCall("not", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } else { if (sort == Sort.INT) { writer.push(-1); @@ -221,14 +227,14 @@ public final class EUnary extends AExpression { } else if (operation == Operation.SUB) { if (sort == Sort.DEF) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type); - writer.invokeDynamic("neg", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.UNARY_OPERATOR, 0); + writer.invokeDefCall("neg", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } else { writer.math(MethodWriter.NEG, actual.type); } } else if (operation == Operation.ADD) { if (sort == Sort.DEF) { org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type); - writer.invokeDynamic("plus", descriptor.getDescriptor(), DEF_BOOTSTRAP_HANDLE, DefBootstrap.UNARY_OPERATOR, 0); + writer.invokeDefCall("plus", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags); } } else { throw createError(new IllegalStateException("Illegal tree structure.")); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java index 02fbb2000f2..93fd21f00b0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java @@ -27,8 +27,6 @@ import org.elasticsearch.painless.Locals; import org.objectweb.asm.Type; import org.elasticsearch.painless.MethodWriter; -import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; - /** * Represents an array load/store or shortcut on a def type. (Internal only.) */ @@ -62,15 +60,15 @@ final class LDefArray extends ALink implements IDefLink { void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); - String desc = Type.getMethodDescriptor(after.type, Definition.DEF_TYPE.type, index.actual.type); - writer.invokeDynamic("arrayLoad", desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.ARRAY_LOAD); + Type methodType = Type.getMethodType(after.type, Definition.DEF_TYPE.type, index.actual.type); + writer.invokeDefCall("arrayLoad", methodType, DefBootstrap.ARRAY_LOAD); } @Override void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); - String desc = Type.getMethodDescriptor(Definition.VOID_TYPE.type, Definition.DEF_TYPE.type, index.actual.type, after.type); - writer.invokeDynamic("arrayStore", desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.ARRAY_STORE); + Type methodType = Type.getMethodType(Definition.VOID_TYPE.type, Definition.DEF_TYPE.type, index.actual.type, after.type); + writer.invokeDefCall("arrayStore", methodType, DefBootstrap.ARRAY_STORE); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java index 716b26d6687..b104ce732ae 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java @@ -30,8 +30,6 @@ import org.objectweb.asm.Type; import java.util.ArrayList; import java.util.List; -import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; - /** * Represents a method call made on a def type. (Internal only.) */ @@ -92,32 +90,30 @@ final class LDefCall extends ALink implements IDefLink { void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); - StringBuilder signature = new StringBuilder(); + List parameterTypes = new ArrayList<>(); - signature.append('('); // first parameter is the receiver, we never know its type: always Object - signature.append(Definition.DEF_TYPE.type.getDescriptor()); + parameterTypes.add(Definition.DEF_TYPE.type); + // append each argument for (AExpression argument : arguments) { - signature.append(argument.actual.type.getDescriptor()); + parameterTypes.add(argument.actual.type); if (argument instanceof ILambda) { ILambda lambda = (ILambda) argument; for (Type capture : lambda.getCaptures()) { - signature.append(capture.getDescriptor()); + parameterTypes.add(capture); } } argument.write(writer, globals); } - signature.append(')'); - // return value - signature.append(after.type.getDescriptor()); + // create method type from return value and arguments + Type methodType = Type.getMethodType(after.type, parameterTypes.toArray(new Type[0])); List args = new ArrayList<>(); - args.add(DefBootstrap.METHOD_CALL); args.add(recipe); args.addAll(pointers); - writer.invokeDynamic(name, signature.toString(), DEF_BOOTSTRAP_HANDLE, args.toArray()); + writer.invokeDefCall(name, methodType, DefBootstrap.METHOD_CALL, args.toArray()); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java index 125b2bee6fc..ba474764cd0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefField.java @@ -27,8 +27,6 @@ import org.elasticsearch.painless.Locals; import org.objectweb.asm.Type; import org.elasticsearch.painless.MethodWriter; -import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; - /** * Represents a field load/store or shortcut on a def type. (Internal only.) */ @@ -59,15 +57,15 @@ final class LDefField extends ALink implements IDefLink { void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); - String desc = Type.getMethodDescriptor(after.type, Definition.DEF_TYPE.type); - writer.invokeDynamic(value, desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.LOAD); + Type methodType = Type.getMethodType(after.type, Definition.DEF_TYPE.type); + writer.invokeDefCall(value, methodType, DefBootstrap.LOAD); } @Override void store(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); - String desc = Type.getMethodDescriptor(Definition.VOID_TYPE.type, Definition.DEF_TYPE.type, after.type); - writer.invokeDynamic(value, desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.STORE); + Type methodType = Type.getMethodType(Definition.VOID_TYPE.type, Definition.DEF_TYPE.type, after.type); + writer.invokeDefCall(value, methodType, DefBootstrap.STORE); } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java index 403b377ea9c..96258de0760 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SEach.java @@ -35,7 +35,6 @@ import org.elasticsearch.painless.Locals.Variable; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; -import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE; import static org.elasticsearch.painless.WriterConstants.ITERATOR_HASNEXT; import static org.elasticsearch.painless.WriterConstants.ITERATOR_NEXT; import static org.elasticsearch.painless.WriterConstants.ITERATOR_TYPE; @@ -193,8 +192,8 @@ public class SEach extends AStatement { if (method == null) { Type itr = Definition.getType("Iterator"); - String desc = org.objectweb.asm.Type.getMethodDescriptor(itr.type, Definition.DEF_TYPE.type); - writer.invokeDynamic("iterator", desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.ITERATOR); + org.objectweb.asm.Type methodType = org.objectweb.asm.Type.getMethodType(itr.type, Definition.DEF_TYPE.type); + writer.invokeDefCall("iterator", methodType, DefBootstrap.ITERATOR); } else if (java.lang.reflect.Modifier.isInterface(method.owner.clazz.getModifiers())) { writer.invokeInterface(method.owner.type, method.method); } else { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java index 8d3db7f811a..2426508d096 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Constant; import org.elasticsearch.painless.Def; import org.elasticsearch.painless.Definition; @@ -143,12 +144,12 @@ public class SFunction extends AStatement { } /** Writes the function to given ClassVisitor. */ - void write (ClassVisitor writer, Globals globals) { + void write (ClassVisitor writer, CompilerSettings settings, Globals globals) { int access = Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC; if (synthetic) { access |= Opcodes.ACC_SYNTHETIC; } - final MethodWriter function = new MethodWriter(access, method.method, writer, globals.getStatements()); + final MethodWriter function = new MethodWriter(access, method.method, writer, globals.getStatements(), settings); write(function, globals); function.endMethod(); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java index 5e932072ce1..6b870c7367d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless.node; +import org.elasticsearch.painless.CompilerSettings; import org.elasticsearch.painless.Constant; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.MethodKey; @@ -59,6 +60,7 @@ public final class SSource extends AStatement { final String name; final String source; final Printer debugStream; + final CompilerSettings settings; final MainMethodReserved reserved; final List functions; final Globals globals; @@ -67,10 +69,11 @@ public final class SSource extends AStatement { private Locals mainMethod; private byte[] bytes; - public SSource(String name, String source, Printer debugStream, MainMethodReserved reserved, Location location, + public SSource(CompilerSettings settings, String name, String source, Printer debugStream, + MainMethodReserved reserved, Location location, List functions, Globals globals, List statements) { super(location); - + this.settings = settings; this.name = name; this.source = source; this.debugStream = debugStream; @@ -151,7 +154,7 @@ public final class SSource extends AStatement { visitor.visitSource(Location.computeSourceName(name, source), null); // Write the constructor: - MethodWriter constructor = new MethodWriter(Opcodes.ACC_PUBLIC, CONSTRUCTOR, visitor, globals.getStatements()); + MethodWriter constructor = new MethodWriter(Opcodes.ACC_PUBLIC, CONSTRUCTOR, visitor, globals.getStatements(), settings); constructor.visitCode(); constructor.loadThis(); constructor.loadArgs(); @@ -160,14 +163,14 @@ public final class SSource extends AStatement { constructor.endMethod(); // Write the execute method: - MethodWriter execute = new MethodWriter(Opcodes.ACC_PUBLIC, EXECUTE, visitor, globals.getStatements()); + MethodWriter execute = new MethodWriter(Opcodes.ACC_PUBLIC, EXECUTE, visitor, globals.getStatements(), settings); execute.visitCode(); write(execute, globals); execute.endMethod(); // Write all functions: for (SFunction function : functions) { - function.write(visitor, globals); + function.write(visitor, settings, globals); } // Write all synthetic functions. Note that this process may add more :) @@ -175,7 +178,7 @@ public final class SSource extends AStatement { List current = new ArrayList<>(globals.getSyntheticMethods().values()); globals.getSyntheticMethods().clear(); for (SFunction function : current) { - function.write(visitor, globals); + function.write(visitor, settings, globals); } } @@ -195,7 +198,7 @@ public final class SSource extends AStatement { // Initialize the constants in a static initializer final MethodWriter clinit = new MethodWriter(Opcodes.ACC_STATIC, - WriterConstants.CLINIT, visitor, globals.getStatements()); + WriterConstants.CLINIT, visitor, globals.getStatements(), settings); for (Constant constant : inits) { constant.initializer.accept(clinit); clinit.putStatic(CLASS_TYPE, constant.name, constant.type); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/CastTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/CastTests.java new file mode 100644 index 00000000000..fcee0ddeb3e --- /dev/null +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/CastTests.java @@ -0,0 +1,298 @@ +/* + * 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.painless; + +/** Tests for explicit casts */ +public class CastTests extends ScriptTestCase { + + /** + * Unary operator with explicit cast + */ + public void testUnaryOperator() { + assertEquals((byte)5, exec("long x = 5L; return (byte) (+x);")); + assertEquals((short)5, exec("long x = 5L; return (short) (+x);")); + assertEquals((char)5, exec("long x = 5L; return (char) (+x);")); + assertEquals(5, exec("long x = 5L; return (int) (+x);")); + assertEquals(5F, exec("long x = 5L; return (float) (+x);")); + assertEquals(5L, exec("long x = 5L; return (long) (+x);")); + assertEquals(5D, exec("long x = 5L; return (double) (+x);")); + } + + /** + * Binary operators with explicit cast + */ + public void testBinaryOperator() { + assertEquals((byte)6, exec("long x = 5L; return (byte) (x + 1);")); + assertEquals((short)6, exec("long x = 5L; return (short) (x + 1);")); + assertEquals((char)6, exec("long x = 5L; return (char) (x + 1);")); + assertEquals(6, exec("long x = 5L; return (int) (x + 1);")); + assertEquals(6F, exec("long x = 5L; return (float) (x + 1);")); + assertEquals(6L, exec("long x = 5L; return (long) (x + 1);")); + assertEquals(6D, exec("long x = 5L; return (double) (x + 1);")); + } + + /** + * Binary compound assignment with explicit cast + */ + public void testBinaryCompoundAssignment() { + assertEquals((byte)6, exec("long x = 5L; return (byte) (x += 1);")); + assertEquals((short)6, exec("long x = 5L; return (short) (x += 1);")); + assertEquals((char)6, exec("long x = 5L; return (char) (x += 1);")); + assertEquals(6, exec("long x = 5L; return (int) (x += 1);")); + assertEquals(6F, exec("long x = 5L; return (float) (x += 1);")); + assertEquals(6L, exec("long x = 5L; return (long) (x += 1);")); + assertEquals(6D, exec("long x = 5L; return (double) (x += 1);")); + } + + /** + * Binary compound prefix with explicit cast + */ + public void testBinaryPrefix() { + assertEquals((byte)6, exec("long x = 5L; return (byte) (++x);")); + assertEquals((short)6, exec("long x = 5L; return (short) (++x);")); + assertEquals((char)6, exec("long x = 5L; return (char) (++x);")); + assertEquals(6, exec("long x = 5L; return (int) (++x);")); + assertEquals(6F, exec("long x = 5L; return (float) (++x);")); + assertEquals(6L, exec("long x = 5L; return (long) (++x);")); + assertEquals(6D, exec("long x = 5L; return (double) (++x);")); + } + + /** + * Binary compound postifx with explicit cast + */ + public void testBinaryPostfix() { + assertEquals((byte)5, exec("long x = 5L; return (byte) (x++);")); + assertEquals((short)5, exec("long x = 5L; return (short) (x++);")); + assertEquals((char)5, exec("long x = 5L; return (char) (x++);")); + assertEquals(5, exec("long x = 5L; return (int) (x++);")); + assertEquals(5F, exec("long x = 5L; return (float) (x++);")); + assertEquals(5L, exec("long x = 5L; return (long) (x++);")); + assertEquals(5D, exec("long x = 5L; return (double) (x++);")); + } + + /** + * Shift operators with explicit cast + */ + public void testShiftOperator() { + assertEquals((byte)10, exec("long x = 5L; return (byte) (x << 1);")); + assertEquals((short)10, exec("long x = 5L; return (short) (x << 1);")); + assertEquals((char)10, exec("long x = 5L; return (char) (x << 1);")); + assertEquals(10, exec("long x = 5L; return (int) (x << 1);")); + assertEquals(10F, exec("long x = 5L; return (float) (x << 1);")); + assertEquals(10L, exec("long x = 5L; return (long) (x << 1);")); + assertEquals(10D, exec("long x = 5L; return (double) (x << 1);")); + } + + /** + * Shift compound assignment with explicit cast + */ + public void testShiftCompoundAssignment() { + assertEquals((byte)10, exec("long x = 5L; return (byte) (x <<= 1);")); + assertEquals((short)10, exec("long x = 5L; return (short) (x <<= 1);")); + assertEquals((char)10, exec("long x = 5L; return (char) (x <<= 1);")); + assertEquals(10, exec("long x = 5L; return (int) (x <<= 1);")); + assertEquals(10F, exec("long x = 5L; return (float) (x <<= 1);")); + assertEquals(10L, exec("long x = 5L; return (long) (x <<= 1);")); + assertEquals(10D, exec("long x = 5L; return (double) (x <<= 1);")); + } + + /** + * Test that without a cast, we fail when conversions would narrow. + */ + public void testIllegalConversions() { + expectScriptThrows(ClassCastException.class, () -> { + exec("long x = 5L; int y = +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("long x = 5L; int y = (x + x); return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("boolean x = true; int y = +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("boolean x = true; int y = (x ^ false); return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("long x = 5L; boolean y = +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("long x = 5L; boolean y = (x + x); return y"); + }); + } + + /** + * Test that even with a cast, some things aren't allowed. + */ + public void testIllegalExplicitConversions() { + expectScriptThrows(ClassCastException.class, () -> { + exec("boolean x = true; int y = (int) +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("boolean x = true; int y = (int) (x ^ false); return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("long x = 5L; boolean y = (boolean) +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("long x = 5L; boolean y = (boolean) (x + x); return y"); + }); + } + + /** + * Currently these do not adopt the return value, we issue a separate cast! + */ + public void testMethodCallDef() { + assertEquals(5, exec("def x = 5; return (int)x.longValue();")); + } + + /** + * Unary operators adopt the return value + */ + public void testUnaryOperatorDef() { + assertEquals((byte)5, exec("def x = 5L; return (byte) (+x);")); + assertEquals((short)5, exec("def x = 5L; return (short) (+x);")); + assertEquals((char)5, exec("def x = 5L; return (char) (+x);")); + assertEquals(5, exec("def x = 5L; return (int) (+x);")); + assertEquals(5F, exec("def x = 5L; return (float) (+x);")); + assertEquals(5L, exec("def x = 5L; return (long) (+x);")); + assertEquals(5D, exec("def x = 5L; return (double) (+x);")); + } + + /** + * Binary operators adopt the return value + */ + public void testBinaryOperatorDef() { + assertEquals((byte)6, exec("def x = 5L; return (byte) (x + 1);")); + assertEquals((short)6, exec("def x = 5L; return (short) (x + 1);")); + assertEquals((char)6, exec("def x = 5L; return (char) (x + 1);")); + assertEquals(6, exec("def x = 5L; return (int) (x + 1);")); + assertEquals(6F, exec("def x = 5L; return (float) (x + 1);")); + assertEquals(6L, exec("def x = 5L; return (long) (x + 1);")); + assertEquals(6D, exec("def x = 5L; return (double) (x + 1);")); + } + + /** + * Binary operators don't yet adopt the return value with compound assignment + */ + public void testBinaryCompoundAssignmentDef() { + assertEquals((byte)6, exec("def x = 5L; return (byte) (x += 1);")); + assertEquals((short)6, exec("def x = 5L; return (short) (x += 1);")); + assertEquals((char)6, exec("def x = 5L; return (char) (x += 1);")); + assertEquals(6, exec("def x = 5L; return (int) (x += 1);")); + assertEquals(6F, exec("def x = 5L; return (float) (x += 1);")); + assertEquals(6L, exec("def x = 5L; return (long) (x += 1);")); + assertEquals(6D, exec("def x = 5L; return (double) (x += 1);")); + } + + /** + * Binary operators don't yet adopt the return value with compound assignment + */ + public void testBinaryCompoundAssignmentPrefix() { + assertEquals((byte)6, exec("def x = 5L; return (byte) (++x);")); + assertEquals((short)6, exec("def x = 5L; return (short) (++x);")); + assertEquals((char)6, exec("def x = 5L; return (char) (++x);")); + assertEquals(6, exec("def x = 5L; return (int) (++x);")); + assertEquals(6F, exec("def x = 5L; return (float) (++x);")); + assertEquals(6L, exec("def x = 5L; return (long) (++x);")); + assertEquals(6D, exec("def x = 5L; return (double) (++x);")); + } + + /** + * Binary operators don't yet adopt the return value with compound assignment + */ + public void testBinaryCompoundAssignmentPostfix() { + assertEquals((byte)5, exec("def x = 5L; return (byte) (x++);")); + assertEquals((short)5, exec("def x = 5L; return (short) (x++);")); + assertEquals((char)5, exec("def x = 5L; return (char) (x++);")); + assertEquals(5, exec("def x = 5L; return (int) (x++);")); + assertEquals(5F, exec("def x = 5L; return (float) (x++);")); + assertEquals(5L, exec("def x = 5L; return (long) (x++);")); + assertEquals(5D, exec("def x = 5L; return (double) (x++);")); + } + + /** + * Shift operators adopt the return value + */ + public void testShiftOperatorDef() { + assertEquals((byte)10, exec("def x = 5L; return (byte) (x << 1);")); + assertEquals((short)10, exec("def x = 5L; return (short) (x << 1);")); + assertEquals((char)10, exec("def x = 5L; return (char) (x << 1);")); + assertEquals(10, exec("def x = 5L; return (int) (x << 1);")); + assertEquals(10F, exec("def x = 5L; return (float) (x << 1);")); + assertEquals(10L, exec("def x = 5L; return (long) (x << 1);")); + assertEquals(10D, exec("def x = 5L; return (double) (x << 1);")); + } + + /** + * Shift operators don't yet adopt the return value with compound assignment + */ + public void testShiftCompoundAssignmentDef() { + assertEquals((byte)10, exec("def x = 5L; return (byte) (x <<= 1);")); + assertEquals((short)10, exec("def x = 5L; return (short) (x <<= 1);")); + assertEquals((char)10, exec("def x = 5L; return (char) (x <<= 1);")); + assertEquals(10, exec("def x = 5L; return (int) (x <<= 1);")); + assertEquals(10F, exec("def x = 5L; return (float) (x <<= 1);")); + assertEquals(10L, exec("def x = 5L; return (long) (x <<= 1);")); + assertEquals(10D, exec("def x = 5L; return (double) (x <<= 1);")); + } + + /** + * Test that without a cast, we fail when conversions would narrow. + */ + public void testIllegalConversionsDef() { + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = 5L; int y = +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = 5L; int y = (x + x); return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = true; int y = +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = true; int y = (x ^ false); return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = 5L; boolean y = +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = 5L; boolean y = (x + x); return y"); + }); + } + + /** + * Test that even with a cast, some things aren't allowed. + * (stuff that methodhandles explicitCastArguments would otherwise allow) + */ + public void testIllegalExplicitConversionsDef() { + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = true; int y = (int) +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = true; int y = (int) (x ^ false); return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = 5L; boolean y = (boolean) +x; return y"); + }); + expectScriptThrows(ClassCastException.class, () -> { + exec("def x = 5L; boolean y = (boolean) (x + x); return y"); + }); + } +} diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java index 6529bed3a48..6babe51334a 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java @@ -36,6 +36,7 @@ public class DefBootstrapTests extends ESTestCase { CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), "toString", MethodType.methodType(String.class, Object.class), + 0, DefBootstrap.METHOD_CALL, 0L); MethodHandle handle = site.dynamicInvoker(); assertDepthEquals(site, 0); @@ -53,6 +54,7 @@ public class DefBootstrapTests extends ESTestCase { CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), "toString", MethodType.methodType(String.class, Object.class), + 0, DefBootstrap.METHOD_CALL, 0L); MethodHandle handle = site.dynamicInvoker(); assertDepthEquals(site, 0); @@ -75,6 +77,7 @@ public class DefBootstrapTests extends ESTestCase { CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), "toString", MethodType.methodType(String.class, Object.class), + 0, DefBootstrap.METHOD_CALL, 0L); MethodHandle handle = site.dynamicInvoker(); assertDepthEquals(site, 0); @@ -98,6 +101,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.PIC site = (DefBootstrap.PIC) DefBootstrap.bootstrap(MethodHandles.publicLookup(), "size", MethodType.methodType(int.class, Object.class), + 0, DefBootstrap.METHOD_CALL, 0L); site.depth = DefBootstrap.PIC.MAX_DEPTH; // mark megamorphic MethodHandle handle = site.dynamicInvoker(); @@ -127,6 +131,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.MIC site = (DefBootstrap.MIC) DefBootstrap.bootstrap(MethodHandles.publicLookup(), "add", MethodType.methodType(Object.class, Object.class, Object.class), + 0, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); MethodHandle handle = site.dynamicInvoker(); assertEquals("nulltest", (Object)handle.invokeExact((Object)null, (Object)"test")); @@ -136,6 +141,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.MIC site = (DefBootstrap.MIC) DefBootstrap.bootstrap(MethodHandles.publicLookup(), "add", MethodType.methodType(Object.class, Object.class, Object.class), + 0, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); MethodHandle handle = site.dynamicInvoker(); assertEquals(2, (Object)handle.invokeExact((Object)1, (Object)1)); @@ -146,6 +152,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.MIC site = (DefBootstrap.MIC) DefBootstrap.bootstrap(MethodHandles.publicLookup(), "eq", MethodType.methodType(boolean.class, Object.class, Object.class), + 0, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); MethodHandle handle = site.dynamicInvoker(); assertFalse((boolean) handle.invokeExact((Object)null, (Object)"test")); @@ -156,6 +163,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.MIC site = (DefBootstrap.MIC) DefBootstrap.bootstrap(MethodHandles.publicLookup(), "eq", MethodType.methodType(boolean.class, Object.class, Object.class), + 0, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); MethodHandle handle = site.dynamicInvoker(); assertTrue((boolean) handle.invokeExact((Object)1, (Object)1)); @@ -171,6 +179,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.MIC site = (DefBootstrap.MIC) DefBootstrap.bootstrap(MethodHandles.publicLookup(), "add", MethodType.methodType(Object.class, int.class, Object.class), + 0, DefBootstrap.BINARY_OPERATOR, 0); MethodHandle handle = site.dynamicInvoker(); expectThrows(NullPointerException.class, () -> { @@ -182,6 +191,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.MIC site = (DefBootstrap.MIC) DefBootstrap.bootstrap(MethodHandles.publicLookup(), "add", MethodType.methodType(Object.class, int.class, Object.class), + 0, DefBootstrap.BINARY_OPERATOR, 0); MethodHandle handle = site.dynamicInvoker(); assertEquals(2, (Object)handle.invokeExact(1, (Object)1)); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefOptimizationTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefOptimizationTests.java index 6fb9151cb0d..fe0f7b6ed82 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefOptimizationTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefOptimizationTests.java @@ -243,18 +243,22 @@ public class DefOptimizationTests extends ScriptTestCase { public void testAddOptNullGuards() { // needs null guard assertBytecodeHasPattern("def x = 1; def y = 2; return x + y", - "(?s).*INVOKEDYNAMIC add.*arguments:\\s+" + DefBootstrap.BINARY_OPERATOR + "(?s).*INVOKEDYNAMIC add.*arguments:\\s+" + "\\d+" + + ",\\s+" + DefBootstrap.BINARY_OPERATOR + ",\\s+" + DefBootstrap.OPERATOR_ALLOWS_NULL + ".*"); // still needs null guard, NPE is the wrong thing! assertBytecodeHasPattern("def x = 1; def y = 2; double z = x + y", - "(?s).*INVOKEDYNAMIC add.*arguments:\\s+" + DefBootstrap.BINARY_OPERATOR + "(?s).*INVOKEDYNAMIC add.*arguments:\\s+" + "\\d+" + + ",\\s+" + DefBootstrap.BINARY_OPERATOR + ",\\s+" + DefBootstrap.OPERATOR_ALLOWS_NULL + ".*"); // a primitive argument is present: no null guard needed assertBytecodeHasPattern("def x = 1; int y = 2; return x + y", - "(?s).*INVOKEDYNAMIC add.*arguments:\\s+" + DefBootstrap.BINARY_OPERATOR + "(?s).*INVOKEDYNAMIC add.*arguments:\\s+" + "\\d+" + + ",\\s+" + DefBootstrap.BINARY_OPERATOR + ",\\s+" + 0 + ".*"); assertBytecodeHasPattern("int x = 1; def y = 2; return x + y", - "(?s).*INVOKEDYNAMIC add.*arguments:\\s+" + DefBootstrap.BINARY_OPERATOR + "(?s).*INVOKEDYNAMIC add.*arguments:\\s+" + "\\d+" + + ",\\s+" + DefBootstrap.BINARY_OPERATOR + ",\\s+" + 0 + ".*"); } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java index 40f59e91120..0bec55b5428 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java @@ -56,6 +56,7 @@ public abstract class ScriptTestCase extends ESTestCase { public Object exec(String script, Map vars) { Map compilerSettings = new HashMap<>(); compilerSettings.put(CompilerSettings.PICKY, "true"); + compilerSettings.put(CompilerSettings.INITIAL_CALL_SITE_DEPTH, random().nextBoolean() ? "0" : "10"); return exec(script, vars, compilerSettings, null); } From 5475e18ad0c7958704d537483ab038ba459ce95a Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 19 Jun 2016 20:16:53 +0200 Subject: [PATCH 51/87] Update forbiddenapis to 2.2 and fix painless tests --- buildSrc/build.gradle | 2 +- .../src/main/resources/forbidden/es-all-signatures.txt | 4 ++-- .../test/java/org/elasticsearch/painless/ArrayTests.java | 8 +++++++- .../org/elasticsearch/painless/DefBootstrapTests.java | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index a5a9b4209ba..cbb97179a46 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -84,7 +84,7 @@ dependencies { compile 'com.netflix.nebula:gradle-info-plugin:3.0.3' compile 'org.eclipse.jgit:org.eclipse.jgit:3.2.0.201312181205-r' compile 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE.... - compile 'de.thetaphi:forbiddenapis:2.1' + compile 'de.thetaphi:forbiddenapis:2.2' compile 'com.bmuschko:gradle-nexus-plugin:2.3.1' compile 'org.apache.rat:apache-rat:0.11' } diff --git a/buildSrc/src/main/resources/forbidden/es-all-signatures.txt b/buildSrc/src/main/resources/forbidden/es-all-signatures.txt index 71eb1433521..37f03f4c91c 100644 --- a/buildSrc/src/main/resources/forbidden/es-all-signatures.txt +++ b/buildSrc/src/main/resources/forbidden/es-all-signatures.txt @@ -32,7 +32,7 @@ org.apache.lucene.index.IndexReader#getCombinedCoreAndDeletesKey() @defaultMessage Soon to be removed org.apache.lucene.document.FieldType#numericType() -@defaultMessage Don't use MethodHandles in slow ways, dont be lenient in tests. -# unfortunately, invoke() cannot be banned, because forbidden apis does not support signature polymorphic methods +@defaultMessage Don't use MethodHandles in slow ways, don't be lenient in tests. +java.lang.invoke.MethodHandle#invoke(java.lang.Object[]) java.lang.invoke.MethodHandle#invokeWithArguments(java.lang.Object[]) java.lang.invoke.MethodHandle#invokeWithArguments(java.util.List) diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ArrayTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ArrayTests.java index e6a5537194d..acacc613ab3 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ArrayTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ArrayTests.java @@ -19,6 +19,9 @@ package org.elasticsearch.painless; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodType; + /** Tests for or operator across all types */ public class ArrayTests extends ScriptTestCase { @@ -36,7 +39,10 @@ public class ArrayTests extends ScriptTestCase { } private void assertArrayLength(int length, Object array) throws Throwable { - assertEquals(length, (int) Def.arrayLengthGetter(array.getClass()).invoke(array)); + final MethodHandle mh = Def.arrayLengthGetter(array.getClass()); + assertSame(array.getClass(), mh.type().parameterType(0)); + assertEquals(length, (int) mh.asType(MethodType.methodType(int.class, Object.class)) + .invokeExact(array)); } public void testArrayLoadStoreInt() { diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java index 6529bed3a48..eb08825f387 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java @@ -139,7 +139,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL); MethodHandle handle = site.dynamicInvoker(); assertEquals(2, (Object)handle.invokeExact((Object)1, (Object)1)); - assertEquals("nulltest", (Object)handle.invoke((Object)null, (Object)"test")); + assertEquals("nulltest", (Object)handle.invokeExact((Object)null, (Object)"test")); } public void testNullGuardEq() throws Throwable { From 6b46bf13f04cd01cb51d3d11ccf259755b7f7253 Mon Sep 17 00:00:00 2001 From: Florian Hopf Date: Sun, 19 Jun 2016 23:25:18 +0200 Subject: [PATCH 52/87] Throw if the local node is not set This commit adds an IllegalStateException if attempting to get the local node from the cluster service when it is not set. Relates #18963 --- .../org/elasticsearch/cluster/service/ClusterService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java b/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java index 7573f260a54..50c91665485 100644 --- a/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java +++ b/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java @@ -237,7 +237,11 @@ public class ClusterService extends AbstractLifecycleComponent { * The local node. */ public DiscoveryNode localNode() { - return clusterState.getNodes().getLocalNode(); + DiscoveryNode localNode = clusterState.getNodes().getLocalNode(); + if (localNode == null) { + throw new IllegalStateException("No local node found. Is the node started?"); + } + return localNode; } public OperationRouting operationRouting() { From 98951b1203a8bc34d39a190a00712b62598adacf Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Thu, 16 Jun 2016 10:39:14 +0200 Subject: [PATCH 53/87] Compile each Groovy script in its own classloader closes #18572 --- .../elasticsearch/script/CompiledScript.java | 6 +- .../script/NativeScriptEngineService.java | 5 - .../script/ScriptEngineService.java | 8 - .../elasticsearch/script/ScriptService.java | 12 +- .../script/ScriptModesTests.java | 6 - .../script/ScriptServiceTests.java | 11 -- .../script/ScriptSettingsTests.java | 6 - .../search/aggregations/metrics/AvgIT.java | 8 - .../search/aggregations/metrics/SumIT.java | 8 - .../aggregations/metrics/ValueCountIT.java | 4 - .../org/elasticsearch/update/UpdateIT.java | 17 -- .../ExpressionScriptEngineService.java | 5 - .../groovy/GroovyScriptEngineService.java | 177 ++++++++---------- .../plugin-metadata/plugin-security.policy | 2 - .../script/groovy/GroovySecurityTests.java | 4 +- .../test/lang_groovy/16_update2.yaml | 2 +- .../mustache/MustacheScriptEngineService.java | 5 - .../painless/PainlessScriptEngineService.java | 9 - .../JavaScriptScriptEngineService.java | 5 - .../python/PythonScriptEngineService.java | 5 - .../script/MockScriptEngine.java | 4 - 21 files changed, 92 insertions(+), 217 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/script/CompiledScript.java b/core/src/main/java/org/elasticsearch/script/CompiledScript.java index aa34678c041..ec2ad4192a2 100644 --- a/core/src/main/java/org/elasticsearch/script/CompiledScript.java +++ b/core/src/main/java/org/elasticsearch/script/CompiledScript.java @@ -39,9 +39,9 @@ public class CompiledScript { public CompiledScript(ScriptService.ScriptType type, String name, String lang, Object compiled) { this.type = type; this.name = name; - this.lang = lang; - this.compiled = compiled; - } + this.lang = lang; + this.compiled = compiled; + } /** * Method to get the type of language. diff --git a/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java b/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java index c9bfdfc1670..191c2b4bcf7 100644 --- a/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java +++ b/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java @@ -90,11 +90,6 @@ public class NativeScriptEngineService extends AbstractComponent implements Scri public void close() { } - @Override - public void scriptRemoved(CompiledScript script) { - // Nothing to do here - } - @Override public boolean isInlineScriptEnabled() { return true; diff --git a/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java b/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java index ab49c3c8011..55a931d8d57 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.search.lookup.SearchLookup; import java.io.Closeable; -import java.util.List; import java.util.Map; /** @@ -49,13 +48,6 @@ public interface ScriptEngineService extends Closeable { SearchScript search(CompiledScript compiledScript, SearchLookup lookup, @Nullable Map vars); - /** - * Handler method called when a script is removed from the Guava cache. - * - * The passed script may be null if it has already been garbage collected. - * */ - void scriptRemoved(@Nullable CompiledScript script); - /** * Returns true if this scripting engine can safely accept inline scripts by default. The default is false */ diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java index fe3eaa29142..8f939f265a4 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java @@ -507,16 +507,10 @@ public class ScriptService extends AbstractComponent implements Closeable { private class ScriptCacheRemovalListener implements RemovalListener { @Override public void onRemoval(RemovalNotification notification) { - scriptMetrics.onCacheEviction(); - for (ScriptEngineService service : scriptEngines) { - try { - service.scriptRemoved(notification.getValue()); - } catch (Exception e) { - logger.warn("exception calling script removal listener for script service", e); - // We don't rethrow because Guava would just catch the - // exception and log it, which we have already done - } + if (logger.isDebugEnabled()) { + logger.debug("removed {} from cache, reason: {}", notification.getValue(), notification.getRemovalReason()); } + scriptMetrics.onCacheEviction(); } } diff --git a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java index 2927b4747dc..e4a1835ab63 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java @@ -257,12 +257,6 @@ public class ScriptModesTests extends ESTestCase { @Override public void close() { - - } - - @Override - public void scriptRemoved(@Nullable CompiledScript script) { - } } } diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index db9e7d66731..597cb7e6032 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -518,11 +518,6 @@ public class ScriptServiceTests extends ESTestCase { } - @Override - public void scriptRemoved(CompiledScript script) { - // Nothing to do here - } - @Override public boolean isInlineScriptEnabled() { return true; @@ -562,12 +557,6 @@ public class ScriptServiceTests extends ESTestCase { @Override public void close() { - - } - - @Override - public void scriptRemoved(CompiledScript script) { - // Nothing to do here } } diff --git a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java index 0e2bb384152..053ccec652c 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java @@ -95,12 +95,6 @@ public class ScriptSettingsTests extends ESTestCase { @Override public void close() { - - } - - @Override - public void scriptRemoved(@Nullable CompiledScript script) { - } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java index ad2c0ddb9d5..ccf03df37fc 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java @@ -456,10 +456,6 @@ public class AvgIT extends AbstractNumericTestCase { } }; } - - @Override - public void scriptRemoved(CompiledScript script) { - } } /** @@ -564,10 +560,6 @@ public class AvgIT extends AbstractNumericTestCase { }; } - @Override - public void scriptRemoved(CompiledScript script) { - } - @Override public boolean isInlineScriptEnabled() { return true; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java index a142f43bd5a..186bc8fb27b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java @@ -453,10 +453,6 @@ public class SumIT extends AbstractNumericTestCase { }; } - @Override - public void scriptRemoved(CompiledScript script) { - } - @Override public boolean isInlineScriptEnabled() { return true; @@ -573,10 +569,6 @@ public class SumIT extends AbstractNumericTestCase { }; } - @Override - public void scriptRemoved(CompiledScript script) { - } - @Override public boolean isInlineScriptEnabled() { return true; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java index d79edcc41b6..7de37fdb6a8 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java @@ -318,10 +318,6 @@ public class ValueCountIT extends ESIntegTestCase { }; } - @Override - public void scriptRemoved(CompiledScript script) { - } - @Override public boolean isInlineScriptEnabled() { return true; diff --git a/core/src/test/java/org/elasticsearch/update/UpdateIT.java b/core/src/test/java/org/elasticsearch/update/UpdateIT.java index 0ae1b4e435a..4121543a7a0 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateIT.java @@ -144,10 +144,6 @@ public class UpdateIT extends ESIntegTestCase { throw new UnsupportedOperationException(); } - @Override - public void scriptRemoved(CompiledScript script) { - } - @Override public boolean isInlineScriptEnabled() { return true; @@ -214,15 +210,10 @@ public class UpdateIT extends ESIntegTestCase { throw new UnsupportedOperationException(); } - @Override - public void scriptRemoved(CompiledScript script) { - } - @Override public boolean isInlineScriptEnabled() { return true; } - } public static class ScriptedUpsertScriptPlugin extends Plugin implements ScriptPlugin { @@ -285,10 +276,6 @@ public class UpdateIT extends ESIntegTestCase { throw new UnsupportedOperationException(); } - @Override - public void scriptRemoved(CompiledScript script) { - } - @Override public boolean isInlineScriptEnabled() { return true; @@ -357,10 +344,6 @@ public class UpdateIT extends ESIntegTestCase { throw new UnsupportedOperationException(); } - @Override - public void scriptRemoved(CompiledScript script) { - } - @Override public boolean isInlineScriptEnabled() { return true; diff --git a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngineService.java b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngineService.java index fdede1e77bc..72a5169593a 100644 --- a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngineService.java +++ b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngineService.java @@ -266,11 +266,6 @@ public class ExpressionScriptEngineService extends AbstractComponent implements @Override public void close() {} - @Override - public void scriptRemoved(CompiledScript script) { - // Nothing to do - } - @Override public boolean isInlineScriptEnabled() { return true; diff --git a/modules/lang-groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java b/modules/lang-groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java index 017e51280c0..105d42c8c86 100644 --- a/modules/lang-groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java +++ b/modules/lang-groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java @@ -33,9 +33,11 @@ import org.codehaus.groovy.classgen.GeneratorContext; import org.codehaus.groovy.control.CompilationFailedException; import org.codehaus.groovy.control.CompilePhase; import org.codehaus.groovy.control.CompilerConfiguration; +import org.codehaus.groovy.control.MultipleCompilationErrorsException; import org.codehaus.groovy.control.SourceUnit; import org.codehaus.groovy.control.customizers.CompilationCustomizer; import org.codehaus.groovy.control.customizers.ImportCustomizer; +import org.codehaus.groovy.control.messages.Message; import org.elasticsearch.SpecialPermission; import org.elasticsearch.bootstrap.BootstrapInfo; import org.elasticsearch.common.Nullable; @@ -49,20 +51,26 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.script.ScoreAccessor; import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.GeneralScriptException; +import org.elasticsearch.script.ScriptException; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.lookup.LeafSearchLookup; import org.elasticsearch.search.lookup.SearchLookup; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.security.AccessControlContext; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import static java.util.Collections.emptyList; + /** * Provides the infrastructure for Groovy as a scripting language for Elasticsearch */ @@ -78,81 +86,40 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri */ public static final String GROOVY_INDY_SETTING_NAME = "indy"; - private final GroovyClassLoader loader; + /** + * Classloader used as a parent classloader for all Groovy scripts + */ + private final ClassLoader loader; public GroovyScriptEngineService(Settings settings) { super(settings); - - ImportCustomizer imports = new ImportCustomizer(); - imports.addStarImports("org.joda.time"); - imports.addStaticStars("java.lang.Math"); - - CompilerConfiguration config = new CompilerConfiguration(); - - config.addCompilationCustomizers(imports); - // Add BigDecimal -> Double transformer - config.addCompilationCustomizers(new GroovyBigDecimalTransformer(CompilePhase.CONVERSION)); - - // always enable invokeDynamic, not the crazy softreference-based stuff - config.getOptimizationOptions().put(GROOVY_INDY_SETTING_NAME, true); - - // Groovy class loader to isolate Groovy-land code - // classloader created here + // Creates the classloader here in order to isolate Groovy-land code final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SpecialPermission()); } - this.loader = AccessController.doPrivileged(new PrivilegedAction() { - @Override - public GroovyClassLoader run() { - // snapshot our context (which has permissions for classes), since the script has none - final AccessControlContext engineContext = AccessController.getContext(); - return new GroovyClassLoader(new ClassLoader(getClass().getClassLoader()) { - @Override - protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - if (sm != null) { - try { - engineContext.checkPermission(new ClassPermission(name)); - } catch (SecurityException e) { - throw new ClassNotFoundException(name, e); - } + this.loader = AccessController.doPrivileged((PrivilegedAction) () -> { + // snapshot our context (which has permissions for classes), since the script has none + AccessControlContext context = AccessController.getContext(); + return new ClassLoader(getClass().getClassLoader()) { + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + if (sm != null) { + try { + context.checkPermission(new ClassPermission(name)); + } catch (SecurityException e) { + throw new ClassNotFoundException(name, e); } - return super.loadClass(name, resolve); } - }, config); - } - }); - } - - @Override - public void close() { - loader.clearCache(); - // close classloader here (why do we do this?) - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new SpecialPermission()); - } - AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Void run() { - try { - loader.close(); - } catch (IOException e) { - logger.warn("Unable to close Groovy loader", e); + return super.loadClass(name, resolve); } - return null; - } + }; }); } @Override - public void scriptRemoved(@Nullable CompiledScript script) { - // script could be null, meaning the script has already been garbage collected - if (script == null || NAME.equals(script.lang())) { - // Clear the cache, this removes old script versions from the - // cache to prevent running out of PermGen space - loader.clearCache(); - } + public void close() throws IOException { + // Nothing to do here } @Override @@ -167,30 +134,34 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri @Override public Object compile(String scriptName, String scriptSource, Map params) { - try { - // we reuse classloader, so do a security check just in case. - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new SpecialPermission()); - } - String fake = MessageDigests.toHexString(MessageDigests.sha1().digest(scriptSource.getBytes(StandardCharsets.UTF_8))); - // same logic as GroovyClassLoader.parseClass() but with a different codesource string: - return AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Class run() { - GroovyCodeSource gcs = new GroovyCodeSource(scriptSource, fake, BootstrapInfo.UNTRUSTED_CODEBASE); - gcs.setCachable(false); - // TODO: we could be more complicated and paranoid, and move this to separate block, to - // sandbox the compilation process itself better. - return loader.parseClass(gcs); - } - }); - } catch (Throwable e) { - if (logger.isTraceEnabled()) { - logger.trace("exception compiling Groovy script:", e); - } - throw new GeneralScriptException("failed to compile groovy script", e); + // Create the script class name + String className = MessageDigests.toHexString(MessageDigests.sha1().digest(scriptSource.getBytes(StandardCharsets.UTF_8))); + + final SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new SpecialPermission()); } + return AccessController.doPrivileged((PrivilegedAction) () -> { + try { + GroovyCodeSource codeSource = new GroovyCodeSource(scriptSource, className, BootstrapInfo.UNTRUSTED_CODEBASE); + codeSource.setCachable(false); + + CompilerConfiguration configuration = new CompilerConfiguration() + .addCompilationCustomizers(new ImportCustomizer().addStarImports("org.joda.time").addStaticStars("java.lang.Math")) + .addCompilationCustomizers(new GroovyBigDecimalTransformer(CompilePhase.CONVERSION)); + + // always enable invokeDynamic, not the crazy softreference-based stuff + configuration.getOptimizationOptions().put(GROOVY_INDY_SETTING_NAME, true); + + GroovyClassLoader groovyClassLoader = new GroovyClassLoader(loader, configuration); + return groovyClassLoader.parseClass(codeSource); + } catch (Throwable e) { + if (logger.isTraceEnabled()) { + logger.trace("Exception compiling Groovy script:", e); + } + throw convertToScriptException("Error compiling script " + className, scriptSource, e); + } + }); } /** @@ -215,7 +186,7 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri } return new GroovyScript(compiledScript, createScript(compiledScript.compiled(), allVars), this.logger); } catch (ReflectiveOperationException e) { - throw new GeneralScriptException("failed to build executable " + compiledScript, e); + throw convertToScriptException("Failed to build executable script", compiledScript.name(), e); } } @@ -235,7 +206,7 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri try { scriptObject = createScript(compiledScript.compiled(), allVars); } catch (ReflectiveOperationException e) { - throw new GeneralScriptException("failed to build search " + compiledScript, e); + throw convertToScriptException("Failed to build search script", compiledScript.name(), e); } return new GroovyScript(compiledScript, scriptObject, leafLookup, logger); } @@ -248,6 +219,29 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri }; } + /** + * Converts a {@link Throwable} to a {@link ScriptException} + */ + private ScriptException convertToScriptException(String message, String source, Throwable cause) { + List stack = new ArrayList<>(); + if (cause instanceof MultipleCompilationErrorsException) { + @SuppressWarnings({"unchecked"}) + List errors = (List) ((MultipleCompilationErrorsException) cause).getErrorCollector().getErrors(); + for (Message error : errors) { + try (StringWriter writer = new StringWriter()) { + error.write(new PrintWriter(writer)); + stack.add(writer.toString()); + } catch (IOException e1) { + logger.error("failed to write compilation error message to the stack", e1); + } + } + } else if (cause instanceof CompilationFailedException) { + CompilationFailedException error = (CompilationFailedException) cause; + stack.add(error.getMessage()); + } + throw new ScriptException(message, cause, stack, source, NAME); + } + public static final class GroovyScript implements ExecutableScript, LeafSearchScript { private final CompiledScript compiledScript; @@ -298,17 +292,12 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri try { // NOTE: we truncate the stack because IndyInterface has security issue (needs getClassLoader) // we don't do a security check just as a tradeoff, it cannot really escalate to anything. - return AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Object run() { - return script.run(); - } - }); + return AccessController.doPrivileged((PrivilegedAction) script::run); } catch (Throwable e) { if (logger.isTraceEnabled()) { logger.trace("failed to run {}", e, compiledScript); } - throw new GeneralScriptException("failed to run " + compiledScript, e); + throw new ScriptException("Error evaluating " + compiledScript.name(), e, emptyList(), "", compiledScript.lang()); } } diff --git a/modules/lang-groovy/src/main/plugin-metadata/plugin-security.policy b/modules/lang-groovy/src/main/plugin-metadata/plugin-security.policy index 82482448677..13d00d6d17c 100644 --- a/modules/lang-groovy/src/main/plugin-metadata/plugin-security.policy +++ b/modules/lang-groovy/src/main/plugin-metadata/plugin-security.policy @@ -26,8 +26,6 @@ grant { permission java.lang.RuntimePermission "accessDeclaredMembers"; permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect"; permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.reflect"; - // needed by GroovyScriptEngineService to close its classloader (why?) - permission java.lang.RuntimePermission "closeClassLoader"; // Allow executing groovy scripts with codesource of /untrusted permission groovy.security.GroovyCodeSourcePermission "/untrusted"; diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java index 51aad9b2fba..96a5343913d 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java @@ -24,7 +24,7 @@ import org.apache.lucene.util.Constants; import org.codehaus.groovy.control.MultipleCompilationErrorsException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; -import org.elasticsearch.script.GeneralScriptException; +import org.elasticsearch.script.ScriptException; import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ESTestCase; @@ -151,7 +151,7 @@ public class GroovySecurityTests extends ESTestCase { try { doTest(script); fail("did not get expected exception"); - } catch (GeneralScriptException expected) { + } catch (ScriptException expected) { Throwable cause = expected.getCause(); assertNotNull(cause); if (exceptionClass.isAssignableFrom(cause.getClass()) == false) { diff --git a/modules/lang-groovy/src/test/resources/rest-api-spec/test/lang_groovy/16_update2.yaml b/modules/lang-groovy/src/test/resources/rest-api-spec/test/lang_groovy/16_update2.yaml index 5e1f99eeeff..5849874c02e 100644 --- a/modules/lang-groovy/src/test/resources/rest-api-spec/test/lang_groovy/16_update2.yaml +++ b/modules/lang-groovy/src/test/resources/rest-api-spec/test/lang_groovy/16_update2.yaml @@ -51,7 +51,7 @@ - do: - catch: /Unable.to.parse.*/ + catch: /script_exception,.+Error.compiling.script.*/ put_script: id: "1" lang: "groovy" diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngineService.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngineService.java index 283a72b02af..2a48567333b 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngineService.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngineService.java @@ -133,11 +133,6 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme // Nothing to do here } - @Override - public void scriptRemoved(CompiledScript script) { - // Nothing to do here - } - // permission checked before doing crazy reflection static final SpecialPermission SPECIAL_PERMISSION = new SpecialPermission(); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java index bb94785d339..ba98c7ee62f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngineService.java @@ -202,15 +202,6 @@ public final class PainlessScriptEngineService extends AbstractComponent impleme }; } - /** - * Action taken when a script is removed from the cache. - * @param script The removed script. - */ - @Override - public void scriptRemoved(final CompiledScript script) { - // Nothing to do. - } - /** * Action taken when the engine is closed. */ diff --git a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index 3ef030bdeb0..3a556ce4429 100644 --- a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -148,11 +148,6 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements @Override public void close() { - - } - - @Override - public void scriptRemoved(@Nullable CompiledScript compiledScript) { // Nothing to do here } diff --git a/plugins/lang-python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java b/plugins/lang-python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java index 26bf1bed6fc..b642b7b0a73 100644 --- a/plugins/lang-python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java +++ b/plugins/lang-python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java @@ -142,11 +142,6 @@ public class PythonScriptEngineService extends AbstractComponent implements Scri interp.cleanup(); } - @Override - public void scriptRemoved(@Nullable CompiledScript compiledScript) { - // Nothing to do - } - public class PythonExecutableScript implements ExecutableScript { private final PyCode code; diff --git a/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java b/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java index 64107f56fa7..61a0cf6c236 100644 --- a/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java +++ b/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java @@ -110,10 +110,6 @@ public class MockScriptEngine implements ScriptEngineService { }; } - @Override - public void scriptRemoved(@Nullable CompiledScript script) { - } - @Override public void close() throws IOException { } From 260f38fd76ec262bb0a84573e1b98af689663a68 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 17 Jun 2016 22:57:00 +0200 Subject: [PATCH 54/87] Remove VersionModule and use Version#current consistently. We pretended to be able to ackt like a different version node for so long it's time to be honest and remove this ability. It's just confusing and where needed and tested we should build dedicated extension points. --- .../resources/checkstyle_suppressions.xml | 1 - .../main/java/org/elasticsearch/Version.java | 15 ------- .../action/main/TransportMainAction.java | 7 ++- .../client/transport/TransportClient.java | 1 - .../TransportClientNodesService.java | 4 +- .../metadata/MetaDataCreateIndexService.java | 6 +-- .../cluster/node/DiscoveryNodeService.java | 6 +-- .../zen/elect/ElectMasterService.java | 4 +- .../zen/ping/unicast/UnicastZenPing.java | 9 ++-- .../BlobStoreIndexShardRepository.java | 3 -- .../java/org/elasticsearch/node/Node.java | 7 ++- .../node/service/NodeService.java | 9 ++-- .../transport/local/LocalTransport.java | 10 +++-- .../transport/netty/NettyTransport.java | 11 +++-- .../elasticsearch/tribe/TribeClientNode.java | 3 +- .../node/tasks/TaskManagerTestCase.java | 2 +- .../MetaDataIndexTemplateServiceTests.java | 2 - .../action/main/MainActionTests.java | 2 +- .../BroadcastReplicationTests.java | 2 +- .../TransportClientNodesServiceTests.java | 2 +- .../MetaDataCreateIndexServiceTests.java | 1 - .../node/DiscoveryNodeServiceTests.java | 4 +- .../common/network/NetworkModuleTests.java | 2 +- .../discovery/DiscoveryModuleTests.java | 4 +- .../discovery/ZenFaultDetectionTests.java | 7 ++- .../zen/ElectMasterServiceTests.java | 5 +-- .../zen/NodeJoinControllerTests.java | 2 +- .../discovery/zen/ZenDiscoveryIT.java | 2 +- .../zen/ping/unicast/UnicastZenPingIT.java | 33 ++++++++++---- .../PublishClusterStateActionTests.java | 45 ++++++++----------- .../elasticsearch/http/HttpServerTests.java | 2 +- .../mapper/DynamicMappingDisabledTests.java | 2 +- .../indices/cluster/ClusterStateChanges.java | 2 +- .../NettySizeHeaderFrameDecoderTests.java | 2 +- .../NettyTransportServiceHandshakeTests.java | 1 - .../transport/TransportModuleTests.java | 4 +- .../netty/NettyScheduledPingTests.java | 4 +- .../transport/netty/NettyTransportIT.java | 4 +- .../netty/NettyTransportMultiPortTests.java | 2 +- .../netty/SimpleNettyTransportTests.java | 2 +- .../azure/AzureUnicastHostsProvider.java | 7 +-- .../ec2/AwsEc2UnicastHostsProvider.java | 7 +-- .../gce/GceUnicastHostsProvider.java | 7 +-- .../repositories/azure/AzureRepositoryF.java | 3 +- .../java/org/elasticsearch/node/MockNode.java | 10 +---- .../test/ESSingleNodeTestCase.java | 7 +-- .../test/InternalTestCluster.java | 5 +-- .../transport/AssertingLocalTransport.java | 5 +-- .../test/transport/MockTransportService.java | 17 +++++-- 49 files changed, 137 insertions(+), 167 deletions(-) diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index 94494a06542..ffad8d37c5b 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -859,7 +859,6 @@ - diff --git a/core/src/main/java/org/elasticsearch/Version.java b/core/src/main/java/org/elasticsearch/Version.java index e77b0f450dd..7e2ffd1dfa0 100644 --- a/core/src/main/java/org/elasticsearch/Version.java +++ b/core/src/main/java/org/elasticsearch/Version.java @@ -22,7 +22,6 @@ package org.elasticsearch; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.SuppressForbidden; -import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; @@ -329,18 +328,4 @@ public class Version { public boolean isRC() { return build > 50 && build < 99; } - - public static class Module extends AbstractModule { - - private final Version version; - - public Module(Version version) { - this.version = version; - } - - @Override - protected void configure() { - bind(Version.class).toInstance(version); - } - } } diff --git a/core/src/main/java/org/elasticsearch/action/main/TransportMainAction.java b/core/src/main/java/org/elasticsearch/action/main/TransportMainAction.java index 6bf60835490..c37268a52de 100644 --- a/core/src/main/java/org/elasticsearch/action/main/TransportMainAction.java +++ b/core/src/main/java/org/elasticsearch/action/main/TransportMainAction.java @@ -37,15 +37,13 @@ import org.elasticsearch.transport.TransportService; public class TransportMainAction extends HandledTransportAction { private final ClusterService clusterService; - private final Version version; @Inject public TransportMainAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, - ClusterService clusterService, Version version) { + ClusterService clusterService) { super(settings, MainAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, MainRequest::new); this.clusterService = clusterService; - this.version = version; } @Override @@ -54,6 +52,7 @@ public class TransportMainAction extends HandledTransportAction indexTemplateFilters, Environment env, NodeServicesProvider nodeServicesProvider, IndexScopedSettings indexScopedSettings) { super(settings); this.clusterService = clusterService; this.indicesService = indicesService; this.allocationService = allocationService; - this.version = version; this.aliasValidator = aliasValidator; this.env = env; this.nodeServicesProvider = nodeServicesProvider; @@ -287,7 +285,7 @@ public class MetaDataCreateIndexService extends AbstractComponent { if (indexSettingsBuilder.get(SETTING_VERSION_CREATED) == null) { DiscoveryNodes nodes = currentState.nodes(); - final Version createdVersion = Version.smallest(version, nodes.getSmallestNonClientNodeVersion()); + final Version createdVersion = Version.smallest(Version.CURRENT, nodes.getSmallestNonClientNodeVersion()); indexSettingsBuilder.put(SETTING_VERSION_CREATED, createdVersion); } diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeService.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeService.java index 177c67f2986..06d0c7dbf24 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeService.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeService.java @@ -46,12 +46,10 @@ public class DiscoveryNodeService extends AbstractComponent { // don't use node.id.seed so it won't be seen as an attribute Setting.longSetting("node_id.seed", 0L, Long.MIN_VALUE, Property.NodeScope); private final List customAttributesProviders = new CopyOnWriteArrayList<>(); - private final Version version; @Inject - public DiscoveryNodeService(Settings settings, Version version) { + public DiscoveryNodeService(Settings settings) { super(settings); - this.version = version; } public static String generateNodeId(Settings settings) { @@ -93,7 +91,7 @@ public class DiscoveryNodeService extends AbstractComponent { } } return new DiscoveryNode(Node.NODE_NAME_SETTING.get(settings), nodeId, publishAddress, attributes, - roles, version); + roles, Version.CURRENT); } public interface CustomAttributesProvider { diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java b/core/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java index 5ff79f112d2..76b7de6da08 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java @@ -53,9 +53,9 @@ public class ElectMasterService extends AbstractComponent { private volatile int minimumMasterNodes; @Inject - public ElectMasterService(Settings settings, Version version) { + public ElectMasterService(Settings settings) { super(settings); - this.minMasterVersion = version.minimumCompatibilityVersion(); + this.minMasterVersion = Version.CURRENT.minimumCompatibilityVersion(); this.minimumMasterNodes = DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.get(settings); logger.debug("using minimum_master_nodes [{}]", minimumMasterNodes); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java b/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java index 0d3c7f9d086..06fc9eae13d 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java @@ -132,8 +132,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen @Inject public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService transportService, - Version version, ElectMasterService electMasterService, - @Nullable Set unicastHostsProviders) { + ElectMasterService electMasterService, @Nullable Set unicastHostsProviders) { super(settings); this.threadPool = threadPool; this.transportService = transportService; @@ -166,7 +165,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen TransportAddress[] addresses = transportService.addressesFromString(host, limitPortCounts); for (TransportAddress address : addresses) { configuredTargetNodes.add(new DiscoveryNode(UNICAST_NODE_PREFIX + unicastNodeIdGenerator.incrementAndGet() + "#", - address, emptyMap(), emptySet(), version.minimumCompatibilityVersion())); + address, emptyMap(), emptySet(), getVersion().minimumCompatibilityVersion())); } } catch (Exception e) { throw new IllegalArgumentException("Failed to resolve address for [" + host + "]", e); @@ -586,4 +585,8 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen } } } + + protected Version getVersion() { + return Version.CURRENT; // for tests + } } diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardRepository.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardRepository.java index 94337ecdbc5..96230459934 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardRepository.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardRepository.java @@ -105,8 +105,6 @@ public class BlobStoreIndexShardRepository extends AbstractComponent implements private RateLimiter restoreRateLimiter; - private RateLimiterListener rateLimiterListener; - private RateLimitingInputStream.Listener snapshotThrottleListener; private RateLimitingInputStream.Listener restoreThrottleListener; @@ -163,7 +161,6 @@ public class BlobStoreIndexShardRepository extends AbstractComponent implements this.chunkSize = chunkSize; this.snapshotRateLimiter = snapshotRateLimiter; this.restoreRateLimiter = restoreRateLimiter; - this.rateLimiterListener = rateLimiterListener; this.snapshotThrottleListener = nanos -> rateLimiterListener.onSnapshotPause(nanos); this.restoreThrottleListener = nanos -> rateLimiterListener.onRestorePause(nanos); this.compress = compress; diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index a2a09938ead..70e0c356ba2 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -174,17 +174,17 @@ public class Node implements Closeable { * @param preparedSettings Base settings to configure the node with */ public Node(Settings preparedSettings) { - this(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), Version.CURRENT, Collections.>emptyList()); + this(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), Collections.>emptyList()); } - protected Node(Environment tmpEnv, Version version, Collection> classpathPlugins) { + protected Node(Environment tmpEnv, Collection> classpathPlugins) { Settings tmpSettings = Settings.builder().put(tmpEnv.settings()) .put(Client.CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE).build(); final List resourcesToClose = new ArrayList<>(); // register everything we need to release in the case of an error tmpSettings = TribeService.processSettings(tmpSettings); ESLogger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(tmpSettings)); - final String displayVersion = version + (Build.CURRENT.isSnapshot() ? "-SNAPSHOT" : ""); + final String displayVersion = Version.CURRENT + (Build.CURRENT.isSnapshot() ? "-SNAPSHOT" : ""); final JvmInfo jvmInfo = JvmInfo.jvmInfo(); logger.info( "version[{}], pid[{}], build[{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]", @@ -247,7 +247,6 @@ public class Node implements Closeable { resourcesToClose.add(clusterService); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); ModulesBuilder modules = new ModulesBuilder(); - modules.add(new Version.Module(version)); // plugin modules must be added here, before others or we can get crazy injection errors... for (Module pluginModule : pluginsService.nodeModules()) { modules.add(pluginModule); diff --git a/core/src/main/java/org/elasticsearch/node/service/NodeService.java b/core/src/main/java/org/elasticsearch/node/service/NodeService.java index 1cbdfe12d2c..6a07565b6cd 100644 --- a/core/src/main/java/org/elasticsearch/node/service/NodeService.java +++ b/core/src/main/java/org/elasticsearch/node/service/NodeService.java @@ -70,14 +70,12 @@ public class NodeService extends AbstractComponent implements Closeable { private volatile Map serviceAttributes = emptyMap(); - private final Version version; - private final Discovery discovery; @Inject public NodeService(Settings settings, ThreadPool threadPool, MonitorService monitorService, Discovery discovery, TransportService transportService, IndicesService indicesService, - PluginsService pluginService, CircuitBreakerService circuitBreakerService, Version version, + PluginsService pluginService, CircuitBreakerService circuitBreakerService, ProcessorsRegistry.Builder processorsRegistryBuilder, ClusterService clusterService, SettingsFilter settingsFilter) { super(settings); this.threadPool = threadPool; @@ -85,7 +83,6 @@ public class NodeService extends AbstractComponent implements Closeable { this.transportService = transportService; this.indicesService = indicesService; this.discovery = discovery; - this.version = version; this.pluginService = pluginService; this.circuitBreakerService = circuitBreakerService; this.clusterService = clusterService; @@ -126,7 +123,7 @@ public class NodeService extends AbstractComponent implements Closeable { } public NodeInfo info() { - return new NodeInfo(version, Build.CURRENT, discovery.localNode(), serviceAttributes, + return new NodeInfo(Version.CURRENT, Build.CURRENT, discovery.localNode(), serviceAttributes, settings, monitorService.osService().info(), monitorService.processService().info(), @@ -141,7 +138,7 @@ public class NodeService extends AbstractComponent implements Closeable { public NodeInfo info(boolean settings, boolean os, boolean process, boolean jvm, boolean threadPool, boolean transport, boolean http, boolean plugin, boolean ingest) { - return new NodeInfo(version, Build.CURRENT, discovery.localNode(), serviceAttributes, + return new NodeInfo(Version.CURRENT, Build.CURRENT, discovery.localNode(), serviceAttributes, settings ? settingsFilter.filter(this.settings) : null, os ? monitorService.osService().info() : null, process ? monitorService.processService().info() : null, diff --git a/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java b/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java index d1ac749e4ac..4caf1a543c0 100644 --- a/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java @@ -77,7 +77,6 @@ public class LocalTransport extends AbstractLifecycleComponent implem public static final String LOCAL_TRANSPORT_THREAD_NAME_PREFIX = "local_transport"; final ThreadPool threadPool; private final ThreadPoolExecutor workers; - private final Version version; private volatile TransportServiceAdapter transportServiceAdapter; private volatile BoundTransportAddress boundAddress; private volatile LocalTransportAddress localAddress; @@ -92,11 +91,10 @@ public class LocalTransport extends AbstractLifecycleComponent implem public static final String TRANSPORT_LOCAL_QUEUE = "transport.local.queue"; @Inject - public LocalTransport(Settings settings, ThreadPool threadPool, Version version, + public LocalTransport(Settings settings, ThreadPool threadPool, NamedWriteableRegistry namedWriteableRegistry, CircuitBreakerService circuitBreakerService) { super(settings); this.threadPool = threadPool; - this.version = version; int workerCount = this.settings.getAsInt(TRANSPORT_LOCAL_WORKERS, EsExecutors.boundedNumberOfProcessors(settings)); int queueSize = this.settings.getAsInt(TRANSPORT_LOCAL_QUEUE, -1); logger.debug("creating [{}] workers, queue_size [{}]", workerCount, queueSize); @@ -207,7 +205,7 @@ public class LocalTransport extends AbstractLifecycleComponent implem @Override public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { - final Version version = Version.smallest(node.getVersion(), this.version); + final Version version = Version.smallest(node.getVersion(), getVersion()); try (BytesStreamOutput stream = new BytesStreamOutput()) { stream.setVersion(version); @@ -404,4 +402,8 @@ public class LocalTransport extends AbstractLifecycleComponent implem public List getLocalAddresses() { return Collections.singletonList("0.0.0.0"); } + + protected Version getVersion() { // for tests + return Version.CURRENT; + } } diff --git a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index a5542f9b403..c9f02066836 100644 --- a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -210,7 +210,6 @@ public class NettyTransport extends AbstractLifecycleComponent implem intSetting("transport.netty.boss_count", 1, 1, Property.NodeScope); protected final NetworkService networkService; - protected final Version version; protected final boolean blockingClient; protected final TimeValue connectTimeout; @@ -254,13 +253,12 @@ public class NettyTransport extends AbstractLifecycleComponent implem final ScheduledPing scheduledPing; @Inject - public NettyTransport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, Version version, + public NettyTransport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, NamedWriteableRegistry namedWriteableRegistry, CircuitBreakerService circuitBreakerService) { super(settings); this.threadPool = threadPool; this.networkService = networkService; this.bigArrays = bigArrays; - this.version = version; this.workerCount = WORKER_COUNT.get(settings); this.blockingClient = TCP_BLOCKING_CLIENT.get(settings); @@ -894,7 +892,7 @@ public class NettyTransport extends AbstractLifecycleComponent implem // we pick the smallest of the 2, to support both backward and forward compatibility // note, this is the only place we need to do this, since from here on, we use the serialized version // as the version to use also when the node receiving this request will send the response with - Version version = Version.smallest(this.version, node.getVersion()); + Version version = Version.smallest(getCurrentVersion(), node.getVersion()); stream.setVersion(version); threadPool.getThreadContext().writeTo(stream); @@ -1401,4 +1399,9 @@ public class NettyTransport extends AbstractLifecycleComponent implem } } } + + protected Version getCurrentVersion() { + // this is just for tests to mock stuff like the nodes version - tests can override this internally + return Version.CURRENT; + } } diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeClientNode.java b/core/src/main/java/org/elasticsearch/tribe/TribeClientNode.java index 688dfe5a92d..02957ab99a4 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeClientNode.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeClientNode.java @@ -19,7 +19,6 @@ package org.elasticsearch.tribe; -import org.elasticsearch.Version; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.node.Node; @@ -32,6 +31,6 @@ import java.util.Collections; */ class TribeClientNode extends Node { TribeClientNode(Settings settings) { - super(new Environment(settings), Version.CURRENT, Collections.>emptyList()); + super(new Environment(settings), Collections.>emptyList()); } } diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java index e317d4e6d7a..eec285e7ffb 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java @@ -167,7 +167,7 @@ public abstract class TaskManagerTestCase extends ESTestCase { public TestNode(String name, ThreadPool threadPool, Settings settings) { clusterService = createClusterService(threadPool); transportService = new TransportService(settings, - new LocalTransport(settings, threadPool, Version.CURRENT, new NamedWriteableRegistry(), + new LocalTransport(settings, threadPool, new NamedWriteableRegistry(), new NoneCircuitBreakerService()), threadPool) { @Override protected TaskManager createTaskManager() { diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/MetaDataIndexTemplateServiceTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/MetaDataIndexTemplateServiceTests.java index 4c3f21f988d..d62fe30f6fa 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/MetaDataIndexTemplateServiceTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/template/put/MetaDataIndexTemplateServiceTests.java @@ -158,7 +158,6 @@ public class MetaDataIndexTemplateServiceTests extends ESSingleNodeTestCase { null, null, null, - Version.CURRENT, null, new HashSet<>(), null, @@ -189,7 +188,6 @@ public class MetaDataIndexTemplateServiceTests extends ESSingleNodeTestCase { clusterService, indicesService, null, - Version.CURRENT, null, new HashSet<>(), null, diff --git a/core/src/test/java/org/elasticsearch/action/main/MainActionTests.java b/core/src/test/java/org/elasticsearch/action/main/MainActionTests.java index ce3fa93d214..2bff71d3c40 100644 --- a/core/src/test/java/org/elasticsearch/action/main/MainActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/main/MainActionTests.java @@ -112,7 +112,7 @@ public class MainActionTests extends ESTestCase { when(clusterService.state()).thenReturn(state); TransportMainAction action = new TransportMainAction(settings, mock(ThreadPool.class), mock(TransportService.class), - mock(ActionFilters.class), mock(IndexNameExpressionResolver.class), clusterService, Version.CURRENT); + mock(ActionFilters.class), mock(IndexNameExpressionResolver.class), clusterService); AtomicReference responseRef = new AtomicReference<>(); action.doExecute(new MainRequest(), new ActionListener() { @Override diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java index abebb61c0b7..e7971dd4c1d 100644 --- a/core/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java @@ -89,7 +89,7 @@ public class BroadcastReplicationTests extends ESTestCase { @Before public void setUp() throws Exception { super.setUp(); - LocalTransport transport = new LocalTransport(Settings.EMPTY, threadPool, Version.CURRENT, new NamedWriteableRegistry(), circuitBreakerService); + LocalTransport transport = new LocalTransport(Settings.EMPTY, threadPool, new NamedWriteableRegistry(), circuitBreakerService); clusterService = createClusterService(threadPool); transportService = new TransportService(clusterService.getSettings(), transport, threadPool); transportService.start(); diff --git a/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java b/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java index 2a32ebd05af..5c07f5e6f25 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java +++ b/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java @@ -102,7 +102,7 @@ public class TransportClientNodesServiceTests extends ESTestCase { transportService.start(); transportService.acceptIncomingRequests(); transportClientNodesService = - new TransportClientNodesService(settings, transportService, threadPool, Version.CURRENT); + new TransportClientNodesService(settings, transportService, threadPool); this.nodesCount = randomIntBetween(1, 10); for (int i = 0; i < nodesCount; i++) { transportClientNodesService.addTransportAddresses(new LocalTransportAddress("node" + i)); diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java index 28a25d17337..04d27020273 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java @@ -212,7 +212,6 @@ public class MetaDataCreateIndexServiceTests extends ESTestCase { null, null, null, - Version.CURRENT, null, new HashSet<>(), null, diff --git a/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeServiceTests.java index c03a5ab06dc..fb38a428a76 100644 --- a/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeServiceTests.java @@ -54,7 +54,7 @@ public class DiscoveryNodeServiceTests extends ESTestCase { } } } - DiscoveryNodeService discoveryNodeService = new DiscoveryNodeService(builder.build(), Version.CURRENT); + DiscoveryNodeService discoveryNodeService = new DiscoveryNodeService(builder.build()); DiscoveryNode discoveryNode = discoveryNodeService.buildLocalNode(DummyTransportAddress.INSTANCE); assertThat(discoveryNode.getRoles(), equalTo(selectedRoles)); assertThat(discoveryNode.getAttributes(), equalTo(expectedAttributes)); @@ -68,7 +68,7 @@ public class DiscoveryNodeServiceTests extends ESTestCase { builder.put("node.attr.attr" + i, "value" + i); expectedAttributes.put("attr" + i, "value" + i); } - DiscoveryNodeService discoveryNodeService = new DiscoveryNodeService(builder.build(), Version.CURRENT); + DiscoveryNodeService discoveryNodeService = new DiscoveryNodeService(builder.build()); int numCustomAttributes = randomIntBetween(0, 5); Map customAttributes = new HashMap<>(); for (int i = 0; i < numCustomAttributes; i++) { diff --git a/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java b/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java index d5fc4630bcf..9868d92129f 100644 --- a/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java +++ b/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java @@ -58,7 +58,7 @@ public class NetworkModuleTests extends ModuleTestCase { static class FakeTransport extends AssertingLocalTransport { public FakeTransport() { - super(null, null, null, null, null); + super(null, null, null, null); } } diff --git a/core/src/test/java/org/elasticsearch/discovery/DiscoveryModuleTests.java b/core/src/test/java/org/elasticsearch/discovery/DiscoveryModuleTests.java index 00ed8a2673c..86c3cd91bff 100644 --- a/core/src/test/java/org/elasticsearch/discovery/DiscoveryModuleTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/DiscoveryModuleTests.java @@ -33,8 +33,8 @@ public class DiscoveryModuleTests extends ModuleTestCase { public static class DummyMasterElectionService extends ElectMasterService { - public DummyMasterElectionService(Settings settings, Version version) { - super(settings, version); + public DummyMasterElectionService(Settings settings) { + super(settings); } } diff --git a/core/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java b/core/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java index 90a3a2e8c1e..c6e55ac9181 100644 --- a/core/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java @@ -141,7 +141,12 @@ public class ZenFaultDetectionTests extends ESTestCase { // trace zenfd actions but keep the default otherwise .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), singleton(TransportLivenessAction.NAME)) .build(), - new LocalTransport(settings, threadPool, version, namedWriteableRegistry, circuitBreakerService), + new LocalTransport(settings, threadPool, namedWriteableRegistry, circuitBreakerService) { + @Override + protected Version getVersion() { + return version; + } + }, threadPool); transportService.start(); transportService.acceptIncomingRequests(); diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ElectMasterServiceTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/ElectMasterServiceTests.java index 498aff28ee6..0f93e5d460c 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/ElectMasterServiceTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/ElectMasterServiceTests.java @@ -35,15 +35,12 @@ import java.util.Set; public class ElectMasterServiceTests extends ESTestCase { ElectMasterService electMasterService() { - return new ElectMasterService(Settings.EMPTY, Version.CURRENT); + return new ElectMasterService(Settings.EMPTY); } List generateRandomNodes() { int count = scaledRandomIntBetween(1, 100); ArrayList nodes = new ArrayList<>(count); - - - for (int i = 0; i < count; i++) { Set roles = new HashSet<>(); if (randomBoolean()) { diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java index 683bebc55a3..e994c376c4d 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java @@ -99,7 +99,7 @@ public class NodeJoinControllerTests extends ESTestCase { setState(clusterService, ClusterState.builder(clusterService.state()).nodes( DiscoveryNodes.builder(initialNodes).masterNodeId(localNode.getId()))); nodeJoinController = new NodeJoinController(clusterService, new NoopAllocationService(Settings.EMPTY), - new ElectMasterService(Settings.EMPTY, Version.CURRENT), + new ElectMasterService(Settings.EMPTY), new DiscoverySettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), Settings.EMPTY); } diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java b/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java index d12a0ff55a3..c5f92e62de0 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java @@ -320,7 +320,7 @@ public class ZenDiscoveryIT extends ESIntegTestCase { } public void testJoinElectedMaster_incompatibleMinVersion() { - ElectMasterService electMasterService = new ElectMasterService(Settings.EMPTY, Version.CURRENT); + ElectMasterService electMasterService = new ElectMasterService(Settings.EMPTY); DiscoveryNode node = new DiscoveryNode("_node_id", new LocalTransportAddress("_id"), emptyMap(), Collections.singleton(DiscoveryNode.Role.MASTER), Version.CURRENT); diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java b/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java index 11816512583..f072c5faf8a 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java @@ -68,7 +68,7 @@ public class UnicastZenPingIT extends ESTestCase { ThreadPool threadPool = new TestThreadPool(getClass().getName()); NetworkService networkService = new NetworkService(settings); - ElectMasterService electMasterService = new ElectMasterService(settings, Version.CURRENT); + ElectMasterService electMasterService = new ElectMasterService(settings); NetworkHandle handleA = startServices(settings, threadPool, networkService, "UZP_A", Version.CURRENT); NetworkHandle handleB = startServices(settings, threadPool, networkService, "UZP_B", Version.CURRENT); @@ -88,7 +88,7 @@ public class UnicastZenPingIT extends ESTestCase { .build(); Settings hostsSettingsMismatch = Settings.builder().put(hostsSettings).put(settingsMismatch).build(); - UnicastZenPing zenPingA = new UnicastZenPing(hostsSettings, threadPool, handleA.transportService, Version.CURRENT, electMasterService, null); + UnicastZenPing zenPingA = new UnicastZenPing(hostsSettings, threadPool, handleA.transportService, electMasterService, null); zenPingA.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { @@ -102,7 +102,7 @@ public class UnicastZenPingIT extends ESTestCase { }); zenPingA.start(); - UnicastZenPing zenPingB = new UnicastZenPing(hostsSettings, threadPool, handleB.transportService, Version.CURRENT, electMasterService, null); + UnicastZenPing zenPingB = new UnicastZenPing(hostsSettings, threadPool, handleB.transportService, electMasterService, null); zenPingB.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { @@ -116,7 +116,13 @@ public class UnicastZenPingIT extends ESTestCase { }); zenPingB.start(); - UnicastZenPing zenPingC = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleC.transportService, versionD, electMasterService, null); + UnicastZenPing zenPingC = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleC.transportService, electMasterService, + null) { + @Override + protected Version getVersion() { + return versionD; + } + }; zenPingC.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { @@ -130,7 +136,7 @@ public class UnicastZenPingIT extends ESTestCase { }); zenPingC.start(); - UnicastZenPing zenPingD = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleD.transportService, Version.CURRENT, electMasterService, null); + UnicastZenPing zenPingD = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleD.transportService, electMasterService, null); zenPingD.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { @@ -191,8 +197,15 @@ public class UnicastZenPingIT extends ESTestCase { } } - private NetworkHandle startServices(Settings settings, ThreadPool threadPool, NetworkService networkService, String nodeId, Version version) { - NettyTransport transport = new NettyTransport(settings, threadPool, networkService, BigArrays.NON_RECYCLING_INSTANCE, version, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); + private NetworkHandle startServices(Settings settings, ThreadPool threadPool, NetworkService networkService, String nodeId, + Version version) { + NettyTransport transport = new NettyTransport(settings, threadPool, networkService, BigArrays.NON_RECYCLING_INSTANCE, + new NamedWriteableRegistry(), new NoneCircuitBreakerService()) { + @Override + protected Version getCurrentVersion() { + return version; + } + }; final TransportService transportService = new TransportService(settings, transport, threadPool); transportService.start(); transportService.acceptIncomingRequests(); @@ -208,7 +221,8 @@ public class UnicastZenPingIT extends ESTestCase { public void onNodeDisconnected(DiscoveryNode node) { } }); - final DiscoveryNode node = new DiscoveryNode(nodeId, transportService.boundAddress().publishAddress(), emptyMap(), emptySet(), version); + final DiscoveryNode node = new DiscoveryNode(nodeId, transportService.boundAddress().publishAddress(), emptyMap(), emptySet(), + version); transportService.setLocalNode(node); return new NetworkHandle((InetSocketTransportAddress)transport.boundAddress().publishAddress(), transportService, node, counters); } @@ -219,7 +233,8 @@ public class UnicastZenPingIT extends ESTestCase { public final DiscoveryNode node; public final ConcurrentMap counters; - public NetworkHandle(InetSocketTransportAddress address, TransportService transportService, DiscoveryNode discoveryNode, ConcurrentMap counters) { + public NetworkHandle(InetSocketTransportAddress address, TransportService transportService, DiscoveryNode discoveryNode, + ConcurrentMap counters) { this.address = address; this.transportService = transportService; this.node = discoveryNode; diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java index ed09efaaada..61374cc0d8f 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java @@ -145,26 +145,22 @@ public class PublishClusterStateActionTests extends ESTestCase { } public MockNode createMockNode(final String name) throws Exception { - return createMockNode(name, Settings.EMPTY, Version.CURRENT); + return createMockNode(name, Settings.EMPTY); } public MockNode createMockNode(String name, Settings settings) throws Exception { - return createMockNode(name, settings, Version.CURRENT); + return createMockNode(name, settings, null); } - public MockNode createMockNode(final String name, Settings settings, Version version) throws Exception { - return createMockNode(name, settings, version, null); - } - - public MockNode createMockNode(String name, Settings settings, Version version, @Nullable ClusterStateListener listener) throws Exception { + public MockNode createMockNode(String name, Settings settings, @Nullable ClusterStateListener listener) throws Exception { settings = Settings.builder() .put("name", name) .put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "", TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING") .put(settings) .build(); - MockTransportService service = buildTransportService(settings, version); - DiscoveryNodeService discoveryNodeService = new DiscoveryNodeService(settings, version); + MockTransportService service = buildTransportService(settings); + DiscoveryNodeService discoveryNodeService = new DiscoveryNodeService(settings); DiscoveryNode discoveryNode = discoveryNodeService.buildLocalNode(service.boundAddress().publishAddress()); MockNode node = new MockNode(discoveryNode, service, listener, logger); node.action = buildPublishClusterStateAction(settings, service, () -> node.clusterState, node); @@ -232,8 +228,8 @@ public class PublishClusterStateActionTests extends ESTestCase { terminate(threadPool); } - protected MockTransportService buildTransportService(Settings settings, Version version) { - MockTransportService transportService = MockTransportService.local(Settings.EMPTY, version, threadPool); + protected MockTransportService buildTransportService(Settings settings) { + MockTransportService transportService = MockTransportService.local(Settings.EMPTY, Version.CURRENT, threadPool); transportService.start(); transportService.acceptIncomingRequests(); return transportService; @@ -257,8 +253,8 @@ public class PublishClusterStateActionTests extends ESTestCase { } public void testSimpleClusterStatePublishing() throws Exception { - MockNode nodeA = createMockNode("nodeA", Settings.EMPTY, Version.CURRENT).setAsMaster(); - MockNode nodeB = createMockNode("nodeB", Settings.EMPTY, Version.CURRENT); + MockNode nodeA = createMockNode("nodeA", Settings.EMPTY).setAsMaster(); + MockNode nodeB = createMockNode("nodeB", Settings.EMPTY); // Initial cluster state ClusterState clusterState = nodeA.clusterState; @@ -286,7 +282,7 @@ public class PublishClusterStateActionTests extends ESTestCase { // Adding new node - this node should get full cluster state while nodeB should still be getting diffs - MockNode nodeC = createMockNode("nodeC", Settings.EMPTY, Version.CURRENT); + MockNode nodeC = createMockNode("nodeC", Settings.EMPTY); // cluster state update 3 - register node C previousClusterState = clusterState; @@ -336,14 +332,11 @@ public class PublishClusterStateActionTests extends ESTestCase { } public void testUnexpectedDiffPublishing() throws Exception { - MockNode nodeA = createMockNode("nodeA", Settings.EMPTY, Version.CURRENT, new ClusterStateListener() { - @Override - public void clusterChanged(ClusterChangedEvent event) { - fail("Shouldn't send cluster state to myself"); - } + MockNode nodeA = createMockNode("nodeA", Settings.EMPTY, event -> { + fail("Shouldn't send cluster state to myself"); }).setAsMaster(); - MockNode nodeB = createMockNode("nodeB", Settings.EMPTY, Version.CURRENT); + MockNode nodeB = createMockNode("nodeB", Settings.EMPTY); // Initial cluster state with both states - the second node still shouldn't get diff even though it's present in the previous cluster state DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(nodeA.nodes()).put(nodeB.discoveryNode).build(); @@ -362,14 +355,14 @@ public class PublishClusterStateActionTests extends ESTestCase { public void testDisablingDiffPublishing() throws Exception { Settings noDiffPublishingSettings = Settings.builder().put(DiscoverySettings.PUBLISH_DIFF_ENABLE_SETTING.getKey(), false).build(); - MockNode nodeA = createMockNode("nodeA", noDiffPublishingSettings, Version.CURRENT, new ClusterStateListener() { + MockNode nodeA = createMockNode("nodeA", noDiffPublishingSettings, new ClusterStateListener() { @Override public void clusterChanged(ClusterChangedEvent event) { fail("Shouldn't send cluster state to myself"); } }); - MockNode nodeB = createMockNode("nodeB", noDiffPublishingSettings, Version.CURRENT, new ClusterStateListener() { + MockNode nodeB = createMockNode("nodeB", noDiffPublishingSettings, new ClusterStateListener() { @Override public void clusterChanged(ClusterChangedEvent event) { assertFalse(event.state().wasReadFromDiff()); @@ -400,7 +393,7 @@ public class PublishClusterStateActionTests extends ESTestCase { int numberOfNodes = randomIntBetween(2, 10); int numberOfIterations = scaledRandomIntBetween(5, 50); Settings settings = Settings.builder().put(DiscoverySettings.PUBLISH_DIFF_ENABLE_SETTING.getKey(), randomBoolean()).build(); - MockNode master = createMockNode("node0", settings, Version.CURRENT, new ClusterStateListener() { + MockNode master = createMockNode("node0", settings, new ClusterStateListener() { @Override public void clusterChanged(ClusterChangedEvent event) { assertProperMetaDataForVersion(event.state().metaData(), event.state().version()); @@ -409,7 +402,7 @@ public class PublishClusterStateActionTests extends ESTestCase { DiscoveryNodes.Builder discoveryNodesBuilder = DiscoveryNodes.builder(master.nodes()); for (int i = 1; i < numberOfNodes; i++) { final String name = "node" + i; - final MockNode node = createMockNode(name, settings, Version.CURRENT, new ClusterStateListener() { + final MockNode node = createMockNode(name, settings, new ClusterStateListener() { @Override public void clusterChanged(ClusterChangedEvent event) { assertProperMetaDataForVersion(event.state().metaData(), event.state().version()); @@ -444,14 +437,14 @@ public class PublishClusterStateActionTests extends ESTestCase { } public void testSerializationFailureDuringDiffPublishing() throws Exception { - MockNode nodeA = createMockNode("nodeA", Settings.EMPTY, Version.CURRENT, new ClusterStateListener() { + MockNode nodeA = createMockNode("nodeA", Settings.EMPTY, new ClusterStateListener() { @Override public void clusterChanged(ClusterChangedEvent event) { fail("Shouldn't send cluster state to myself"); } }).setAsMaster(); - MockNode nodeB = createMockNode("nodeB", Settings.EMPTY, Version.CURRENT); + MockNode nodeB = createMockNode("nodeB", Settings.EMPTY); // Initial cluster state with both states - the second node still shouldn't get diff even though it's present in the previous cluster state DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(nodeA.nodes()).put(nodeB.discoveryNode).build(); diff --git a/core/src/test/java/org/elasticsearch/http/HttpServerTests.java b/core/src/test/java/org/elasticsearch/http/HttpServerTests.java index 32f9bbbd84c..2ba7da84c14 100644 --- a/core/src/test/java/org/elasticsearch/http/HttpServerTests.java +++ b/core/src/test/java/org/elasticsearch/http/HttpServerTests.java @@ -74,7 +74,7 @@ public class HttpServerTests extends ESTestCase { ClusterService clusterService = new ClusterService(Settings.EMPTY, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null); - NodeService nodeService = new NodeService(Settings.EMPTY, null, null, null, null, null, null, null, null, null, + NodeService nodeService = new NodeService(Settings.EMPTY, null, null, null, null, null, null, null, null, clusterService, null); httpServer = new HttpServer(settings, httpServerTransport, restController, nodeService, circuitBreakerService); httpServer.start(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java index cc8b05819c6..f9fb5e77b70 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingDisabledTests.java @@ -76,7 +76,7 @@ public class DynamicMappingDisabledTests extends ESSingleNodeTestCase { .build(); clusterService = createClusterService(THREAD_POOL); transport = - new LocalTransport(settings, THREAD_POOL, Version.CURRENT, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); + new LocalTransport(settings, THREAD_POOL, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL); indicesService = getInstanceFromNode(IndicesService.class); shardStateAction = new ShardStateAction(settings, clusterService, transportService, null, null, THREAD_POOL); diff --git a/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java b/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java index 86d19ae1ea4..fc5b68f87d1 100644 --- a/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java +++ b/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java @@ -158,7 +158,7 @@ public class ClusterStateChanges { MetaDataUpdateSettingsService metaDataUpdateSettingsService = new MetaDataUpdateSettingsService(settings, clusterService, allocationService, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, new IndexNameExpressionResolver(settings)); MetaDataCreateIndexService createIndexService = new MetaDataCreateIndexService(settings, clusterService, indicesService, - allocationService, Version.CURRENT, new AliasValidator(settings), Collections.emptySet(), environment, + allocationService, new AliasValidator(settings), Collections.emptySet(), environment, nodeServicesProvider, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS); transportCloseIndexAction = new TransportCloseIndexAction(settings, transportService, clusterService, threadPool, diff --git a/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java b/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java index 95ec6dad9bd..f436b719260 100644 --- a/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java +++ b/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java @@ -66,7 +66,7 @@ public class NettySizeHeaderFrameDecoderTests extends ESTestCase { threadPool = new ThreadPool(settings); NetworkService networkService = new NetworkService(settings); BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); - nettyTransport = new NettyTransport(settings, threadPool, networkService, bigArrays, Version.CURRENT, new NamedWriteableRegistry(), + nettyTransport = new NettyTransport(settings, threadPool, networkService, bigArrays, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); nettyTransport.start(); TransportService transportService = new TransportService(settings, nettyTransport, threadPool); diff --git a/core/src/test/java/org/elasticsearch/transport/NettyTransportServiceHandshakeTests.java b/core/src/test/java/org/elasticsearch/transport/NettyTransportServiceHandshakeTests.java index 2213d7eb4cf..7bbd6e0fea7 100644 --- a/core/src/test/java/org/elasticsearch/transport/NettyTransportServiceHandshakeTests.java +++ b/core/src/test/java/org/elasticsearch/transport/NettyTransportServiceHandshakeTests.java @@ -64,7 +64,6 @@ public class NettyTransportServiceHandshakeTests extends ESTestCase { threadPool, new NetworkService(settings), BigArrays.NON_RECYCLING_INSTANCE, - Version.CURRENT, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); TransportService transportService = new MockTransportService(settings, transport, threadPool); diff --git a/core/src/test/java/org/elasticsearch/transport/TransportModuleTests.java b/core/src/test/java/org/elasticsearch/transport/TransportModuleTests.java index 20413888281..e5c734cbfb6 100644 --- a/core/src/test/java/org/elasticsearch/transport/TransportModuleTests.java +++ b/core/src/test/java/org/elasticsearch/transport/TransportModuleTests.java @@ -36,9 +36,9 @@ public class TransportModuleTests extends ModuleTestCase { static class FakeTransport extends AssertingLocalTransport { @Inject - public FakeTransport(Settings settings, CircuitBreakerService circuitBreakerService, ThreadPool threadPool, Version version, + public FakeTransport(Settings settings, CircuitBreakerService circuitBreakerService, ThreadPool threadPool, NamedWriteableRegistry namedWriteableRegistry) { - super(settings, circuitBreakerService, threadPool, version, namedWriteableRegistry); + super(settings, circuitBreakerService, threadPool, namedWriteableRegistry); } } diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java index a98a038f6fd..df7dcb0714b 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java @@ -65,14 +65,14 @@ public class NettyScheduledPingTests extends ESTestCase { NamedWriteableRegistry registryA = new NamedWriteableRegistry(); final NettyTransport nettyA = new NettyTransport(settings, threadPool, new NetworkService(settings), - BigArrays.NON_RECYCLING_INSTANCE, Version.CURRENT, registryA, circuitBreakerService); + BigArrays.NON_RECYCLING_INSTANCE, registryA, circuitBreakerService); MockTransportService serviceA = new MockTransportService(settings, nettyA, threadPool); serviceA.start(); serviceA.acceptIncomingRequests(); NamedWriteableRegistry registryB = new NamedWriteableRegistry(); final NettyTransport nettyB = new NettyTransport(settings, threadPool, new NetworkService(settings), - BigArrays.NON_RECYCLING_INSTANCE, Version.CURRENT, registryB, circuitBreakerService); + BigArrays.NON_RECYCLING_INSTANCE, registryB, circuitBreakerService); MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool); serviceB.start(); diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java index f70c7b27492..2f89435c6df 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java @@ -93,9 +93,9 @@ public class NettyTransportIT extends ESIntegTestCase { @Inject public ExceptionThrowingNettyTransport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, - Version version, NamedWriteableRegistry namedWriteableRegistry, + NamedWriteableRegistry namedWriteableRegistry, CircuitBreakerService circuitBreakerService) { - super(settings, threadPool, networkService, bigArrays, version, namedWriteableRegistry, circuitBreakerService); + super(settings, threadPool, networkService, bigArrays, namedWriteableRegistry, circuitBreakerService); } @Override diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortTests.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortTests.java index 0ed0cf3ec97..6fdc214d18d 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortTests.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortTests.java @@ -136,7 +136,7 @@ public class NettyTransportMultiPortTests extends ESTestCase { private NettyTransport startNettyTransport(Settings settings, ThreadPool threadPool) { BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); - NettyTransport nettyTransport = new NettyTransport(settings, threadPool, new NetworkService(settings), bigArrays, Version.CURRENT, + NettyTransport nettyTransport = new NettyTransport(settings, threadPool, new NetworkService(settings), bigArrays, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); nettyTransport.start(); diff --git a/core/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java b/core/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java index f3cfcc3bebe..96275d099db 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java @@ -42,7 +42,7 @@ public class SimpleNettyTransportTests extends AbstractSimpleTransportTestCase { @Override protected MockTransportService build(Settings settings, Version version) { settings = Settings.builder().put(settings).put(TransportSettings.PORT.getKey(), "0").build(); - MockTransportService transportService = MockTransportService.nettyFromThreadPool(settings, version, threadPool); + MockTransportService transportService = MockTransportService.nettyFromThreadPool(settings, threadPool, version); transportService.start(); return transportService; } diff --git a/plugins/discovery-azure/src/main/java/org/elasticsearch/discovery/azure/AzureUnicastHostsProvider.java b/plugins/discovery-azure/src/main/java/org/elasticsearch/discovery/azure/AzureUnicastHostsProvider.java index 869fda5f8e2..cb6c8238bf5 100644 --- a/plugins/discovery-azure/src/main/java/org/elasticsearch/discovery/azure/AzureUnicastHostsProvider.java +++ b/plugins/discovery-azure/src/main/java/org/elasticsearch/discovery/azure/AzureUnicastHostsProvider.java @@ -101,7 +101,6 @@ public class AzureUnicastHostsProvider extends AbstractComponent implements Unic private final AzureComputeService azureComputeService; private TransportService transportService; private NetworkService networkService; - private final Version version; private final TimeValue refreshInterval; private long lastRefresh; @@ -114,13 +113,11 @@ public class AzureUnicastHostsProvider extends AbstractComponent implements Unic @Inject public AzureUnicastHostsProvider(Settings settings, AzureComputeService azureComputeService, TransportService transportService, - NetworkService networkService, - Version version) { + NetworkService networkService) { super(settings); this.azureComputeService = azureComputeService; this.transportService = transportService; this.networkService = networkService; - this.version = version; this.refreshInterval = Discovery.REFRESH_SETTING.get(settings); @@ -253,7 +250,7 @@ public class AzureUnicastHostsProvider extends AbstractComponent implements Unic for (TransportAddress address : addresses) { logger.trace("adding {}, transport_address {}", networkAddress, address); cachedDiscoNodes.add(new DiscoveryNode("#cloud-" + instance.getInstanceName(), address, emptyMap(), - emptySet(), version.minimumCompatibilityVersion())); + emptySet(), Version.CURRENT.minimumCompatibilityVersion())); } } catch (Exception e) { logger.warn("can not convert [{}] to transport address. skipping. [{}]", networkAddress, e.getMessage()); diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java index 58be8645131..1f3043fe6dd 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java @@ -59,8 +59,6 @@ public class AwsEc2UnicastHostsProvider extends AbstractComponent implements Uni private final AmazonEC2 client; - private final Version version; - private final boolean bindAnyGroup; private final Set groups; @@ -74,11 +72,10 @@ public class AwsEc2UnicastHostsProvider extends AbstractComponent implements Uni private final DiscoNodesCache discoNodes; @Inject - public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportService, AwsEc2Service awsEc2Service, Version version) { + public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportService, AwsEc2Service awsEc2Service) { super(settings); this.transportService = transportService; this.client = awsEc2Service.client(); - this.version = version; this.hostType = DISCOVERY_EC2.HOST_TYPE_SETTING.get(settings); this.discoNodes = new DiscoNodesCache(DISCOVERY_EC2.NODE_CACHE_TIME_SETTING.get(settings)); @@ -175,7 +172,7 @@ public class AwsEc2UnicastHostsProvider extends AbstractComponent implements Uni for (int i = 0; i < addresses.length; i++) { logger.trace("adding {}, address {}, transport_address {}", instance.getInstanceId(), address, addresses[i]); discoNodes.add(new DiscoveryNode("#cloud-" + instance.getInstanceId() + "-" + i, addresses[i], - emptyMap(), emptySet(), version.minimumCompatibilityVersion())); + emptyMap(), emptySet(), Version.CURRENT.minimumCompatibilityVersion())); } } catch (Exception e) { logger.warn("failed ot add {}, address {}", e, instance.getInstanceId(), address); diff --git a/plugins/discovery-gce/src/main/java/org/elasticsearch/discovery/gce/GceUnicastHostsProvider.java b/plugins/discovery-gce/src/main/java/org/elasticsearch/discovery/gce/GceUnicastHostsProvider.java index 29332f61678..c9dd2263245 100644 --- a/plugins/discovery-gce/src/main/java/org/elasticsearch/discovery/gce/GceUnicastHostsProvider.java +++ b/plugins/discovery-gce/src/main/java/org/elasticsearch/discovery/gce/GceUnicastHostsProvider.java @@ -68,7 +68,6 @@ public class GceUnicastHostsProvider extends AbstractComponent implements Unicas private TransportService transportService; private NetworkService networkService; - private final Version version; private final String project; private final List zones; private final List tags; @@ -80,13 +79,11 @@ public class GceUnicastHostsProvider extends AbstractComponent implements Unicas @Inject public GceUnicastHostsProvider(Settings settings, GceComputeService gceComputeService, TransportService transportService, - NetworkService networkService, - Version version) { + NetworkService networkService) { super(settings); this.gceComputeService = gceComputeService; this.transportService = transportService; this.networkService = networkService; - this.version = version; this.refreshInterval = GceComputeService.REFRESH_SETTING.get(settings); this.project = GceComputeService.PROJECT_SETTING.get(settings); @@ -244,7 +241,7 @@ public class GceUnicastHostsProvider extends AbstractComponent implements Unicas logger.trace("adding {}, type {}, address {}, transport_address {}, status {}", name, type, ip_private, transportAddress, status); cachedDiscoNodes.add(new DiscoveryNode("#cloud-" + name + "-" + 0, transportAddress, - emptyMap(), emptySet(), version.minimumCompatibilityVersion())); + emptyMap(), emptySet(), Version.CURRENT.minimumCompatibilityVersion())); } } } catch (Exception e) { diff --git a/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositoryF.java b/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositoryF.java index 4150fe54979..bfa06219127 100644 --- a/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositoryF.java +++ b/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositoryF.java @@ -21,7 +21,6 @@ package org.elasticsearch.repositories.azure; import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.Version; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; @@ -111,7 +110,7 @@ public class AzureRepositoryF { // settings.put("cloud.azure.storage.my_account2.key", "account_key_secondary"); final CountDownLatch latch = new CountDownLatch(1); - final Node node = new MockNode(settings.build(), Version.CURRENT, Collections.singletonList(AzureRepositoryPlugin.class)); + final Node node = new MockNode(settings.build(), Collections.singletonList(AzureRepositoryPlugin.class)); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { diff --git a/test/framework/src/main/java/org/elasticsearch/node/MockNode.java b/test/framework/src/main/java/org/elasticsearch/node/MockNode.java index 57dcc08f4fe..749f1f3279e 100644 --- a/test/framework/src/main/java/org/elasticsearch/node/MockNode.java +++ b/test/framework/src/main/java/org/elasticsearch/node/MockNode.java @@ -35,13 +35,10 @@ import java.util.Collection; */ public class MockNode extends Node { - // these are kept here so a copy of this MockNode can be created, since Node does not store them - private Version version; private Collection> plugins; - public MockNode(Settings settings, Version version, Collection> classpathPlugins) { - super(InternalSettingsPreparer.prepareEnvironment(settings, null), version, classpathPlugins); - this.version = version; + public MockNode(Settings settings, Collection> classpathPlugins) { + super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins); this.plugins = classpathPlugins; } @@ -49,7 +46,4 @@ public class MockNode extends Node { return plugins; } - public Version getVersion() { - return version; - } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java index 4cf058a6a5d..8f06e75b038 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java @@ -19,7 +19,6 @@ package org.elasticsearch.test; import org.apache.lucene.util.IOUtils; -import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; @@ -147,10 +146,6 @@ public abstract class ESSingleNodeTestCase extends ESTestCase { return false; } - /** The version of elasticsearch the node should act like. */ - protected Version getVersion() { - return Version.CURRENT; - } /** The plugin classes that should be added to the node. */ protected Collection> getPlugins() { @@ -187,7 +182,7 @@ public abstract class ESSingleNodeTestCase extends ESTestCase { .put(Node.NODE_DATA_SETTING.getKey(), true) .put(nodeSettings()) // allow test cases to provide their own settings or override these .build(); - Node build = new MockNode(settings, getVersion(), getPlugins()); + Node build = new MockNode(settings, getPlugins()); build.start(); assertThat(DiscoveryNode.isLocalNode(build.settings()), is(true)); return build; diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index bb33ad17dde..950653cba5e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -614,7 +614,7 @@ public final class InternalTestCluster extends TestCluster { .put("node.name", name) .put(DiscoveryNodeService.NODE_ID_SEED_SETTING.getKey(), seed) .build(); - MockNode node = new MockNode(finalSettings, version, plugins); + MockNode node = new MockNode(finalSettings, plugins); return new NodeAndClient(name, node); } @@ -888,8 +888,7 @@ public final class InternalTestCluster extends TestCluster { final long newIdSeed = DiscoveryNodeService.NODE_ID_SEED_SETTING.get(node.settings()) + 1; // use a new seed to make sure we have new node id Settings finalSettings = Settings.builder().put(node.settings()).put(newSettings).put(DiscoveryNodeService.NODE_ID_SEED_SETTING.getKey(), newIdSeed).build(); Collection> plugins = node.getPlugins(); - Version version = node.getVersion(); - node = new MockNode(finalSettings, version, plugins); + node = new MockNode(finalSettings, plugins); node.start(); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/AssertingLocalTransport.java b/test/framework/src/main/java/org/elasticsearch/test/transport/AssertingLocalTransport.java index 0dd8edb75f8..0142acf8c17 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/AssertingLocalTransport.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/AssertingLocalTransport.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; @@ -75,8 +74,8 @@ public class AssertingLocalTransport extends LocalTransport { @Inject public AssertingLocalTransport(Settings settings, CircuitBreakerService circuitBreakerService, ThreadPool threadPool, - Version version, NamedWriteableRegistry namedWriteableRegistry) { - super(settings, threadPool, version, namedWriteableRegistry, circuitBreakerService); + NamedWriteableRegistry namedWriteableRegistry) { + super(settings, threadPool, namedWriteableRegistry, circuitBreakerService); final long seed = ESIntegTestCase.INDEX_TEST_SEED_SETTING.get(settings); random = new Random(seed); minVersion = ASSERTING_TRANSPORT_MIN_VERSION_KEY.get(settings); diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java index 110850e9a0f..7688e2842e6 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java @@ -96,17 +96,26 @@ public class MockTransportService extends TransportService { public static MockTransportService local(Settings settings, Version version, ThreadPool threadPool) { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); - Transport transport = new LocalTransport(settings, threadPool, version, namedWriteableRegistry, new NoneCircuitBreakerService()); + Transport transport = new LocalTransport(settings, threadPool, namedWriteableRegistry, new NoneCircuitBreakerService()) { + @Override + protected Version getVersion() { + return version; + } + }; return new MockTransportService(settings, transport, threadPool); } public static MockTransportService nettyFromThreadPool( Settings settings, - Version version, - ThreadPool threadPool) { + ThreadPool threadPool, final Version version) { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); Transport transport = new NettyTransport(settings, threadPool, new NetworkService(settings), BigArrays.NON_RECYCLING_INSTANCE, - version, namedWriteableRegistry, new NoneCircuitBreakerService()); + namedWriteableRegistry, new NoneCircuitBreakerService()) { + @Override + protected Version getCurrentVersion() { + return version; + } + }; return new MockTransportService(Settings.EMPTY, transport, threadPool); } From b53d7356023b5b62ea47536e7df6f36d321dfe8c Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 05:05:34 -0400 Subject: [PATCH 55/87] Function/Lambda parameters do not need to be lenient... --- .../src/main/java/org/elasticsearch/painless/Locals.java | 4 ++-- .../java/org/elasticsearch/painless/LambdaTests.java | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java index 0893a51bc47..7ffa0a169b7 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java @@ -74,7 +74,7 @@ public final class Locals { for (int i = 0; i < parameters.size(); i++) { Parameter parameter = parameters.get(i); boolean isCapture = i < captureCount; - locals.defineVariable(parameter.location, parameter.type, parameter.name, isCapture); + locals.addVariable(parameter.location, parameter.type, parameter.name, isCapture); } // Loop counter to catch infinite loops. Internal use only. if (maxLoopCounter > 0) { @@ -87,7 +87,7 @@ public final class Locals { public static Locals newFunctionScope(Locals programScope, Type returnType, List parameters, int maxLoopCounter) { Locals locals = new Locals(programScope, returnType); for (Parameter parameter : parameters) { - locals.defineVariable(parameter.location, parameter.type, parameter.name, false); + locals.addVariable(parameter.location, parameter.type, parameter.name, false); } // Loop counter to catch infinite loops. Internal use only. if (maxLoopCounter > 0) { diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java index 22abb8f5255..3b008d5d6b6 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java @@ -125,6 +125,15 @@ public class LambdaTests extends ScriptTestCase { + "return l.stream().mapToInt(x -> { x += 1; return x }).sum();")); } + /** Lambda parameters shouldn't be able to mask a variable already in scope */ + public void testNoParamMasking() { + IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { + exec("int x = 0; List l = new ArrayList(); l.add(1); l.add(1); " + + "return l.stream().mapToInt(x -> { x += 1; return x }).sum();"); + }); + assertTrue(expected.getMessage().contains("already defined")); + } + public void testCaptureDef() { assertEquals(5, exec("int x = 5; def y = Optional.empty(); y.orElseGet(() -> x);")); } From 7fea5bd8e7c45e5a5aaa05881d0fc2e8ba5b978f Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 20 Jun 2016 11:28:14 +0200 Subject: [PATCH 56/87] Remove obsolete Modules that can simply be inlined in node creation --- .../elasticsearch/env/EnvironmentModule.java | 43 ----------------- .../env/NodeEnvironmentModule.java | 48 ------------------- .../elasticsearch/gateway/GatewayModule.java | 5 -- .../java/org/elasticsearch/node/Node.java | 24 ++++++---- .../org/elasticsearch/tribe/TribeModule.java | 32 ------------- .../org/elasticsearch/tribe/TribeService.java | 2 - .../watcher/ResourceWatcherModule.java | 31 ------------ .../script/NativeScriptTests.java | 8 ++-- .../aggregations/AggregatorParsingTests.java | 7 ++- .../aggregations/BaseAggregationTestCase.java | 6 ++- .../BasePipelineAggregationTestCase.java | 6 ++- .../builder/SearchSourceBuilderTests.java | 6 ++- .../messy/tests/TemplateQueryParserTests.java | 7 +-- .../discovery/ec2/Ec2DiscoveryTests.java | 13 ++--- .../discovery/gce/GceDiscoveryTests.java | 6 +-- .../test/AbstractQueryTestCase.java | 16 ++----- 16 files changed, 51 insertions(+), 209 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/env/EnvironmentModule.java delete mode 100644 core/src/main/java/org/elasticsearch/env/NodeEnvironmentModule.java delete mode 100644 core/src/main/java/org/elasticsearch/tribe/TribeModule.java delete mode 100644 core/src/main/java/org/elasticsearch/watcher/ResourceWatcherModule.java diff --git a/core/src/main/java/org/elasticsearch/env/EnvironmentModule.java b/core/src/main/java/org/elasticsearch/env/EnvironmentModule.java deleted file mode 100644 index 6a893a73437..00000000000 --- a/core/src/main/java/org/elasticsearch/env/EnvironmentModule.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.env; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.threadpool.ThreadPool; - -/** - * - */ -public class EnvironmentModule extends AbstractModule { - - private final Environment environment; - private final ThreadPool threadPool; - - public EnvironmentModule(Environment environment, ThreadPool threadPool) { - this.threadPool = threadPool; - this.environment = environment; - } - - @Override - protected void configure() { - bind(ThreadPool.class).toInstance(threadPool); - bind(Environment.class).toInstance(environment); - } -} diff --git a/core/src/main/java/org/elasticsearch/env/NodeEnvironmentModule.java b/core/src/main/java/org/elasticsearch/env/NodeEnvironmentModule.java deleted file mode 100644 index 162c3108120..00000000000 --- a/core/src/main/java/org/elasticsearch/env/NodeEnvironmentModule.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.env; - -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.inject.AbstractModule; - -/** - * - */ -public class NodeEnvironmentModule extends AbstractModule { - - private final NodeEnvironment nodeEnvironment; - - public NodeEnvironmentModule() { - this(null); - } - - public NodeEnvironmentModule(@Nullable NodeEnvironment nodeEnvironment) { - this.nodeEnvironment = nodeEnvironment; - } - - @Override - protected void configure() { - if (nodeEnvironment != null) { - bind(NodeEnvironment.class).toInstance(nodeEnvironment); - } else { - bind(NodeEnvironment.class).asEagerSingleton(); - } - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/gateway/GatewayModule.java b/core/src/main/java/org/elasticsearch/gateway/GatewayModule.java index 651123882a5..f736c070272 100644 --- a/core/src/main/java/org/elasticsearch/gateway/GatewayModule.java +++ b/core/src/main/java/org/elasticsearch/gateway/GatewayModule.java @@ -27,11 +27,6 @@ import org.elasticsearch.common.settings.Settings; */ public class GatewayModule extends AbstractModule { - private final Settings settings; - - public GatewayModule(Settings settings) { - this.settings = settings; - } @Override protected void configure() { diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 70e0c356ba2..2069320104a 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -67,9 +67,7 @@ import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.env.NodeEnvironmentModule; import org.elasticsearch.gateway.GatewayAllocator; import org.elasticsearch.gateway.GatewayModule; import org.elasticsearch.gateway.GatewayService; @@ -104,9 +102,7 @@ import org.elasticsearch.tasks.TaskPersistenceService; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.tribe.TribeModule; import org.elasticsearch.tribe.TribeService; -import org.elasticsearch.watcher.ResourceWatcherModule; import org.elasticsearch.watcher.ResourceWatcherService; import java.io.BufferedWriter; @@ -242,9 +238,13 @@ public class Node implements Closeable { } catch (IOException ex) { throw new IllegalStateException("Failed to created node environment", ex); } + final ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, threadPool); + resourcesToClose.add(resourceWatcherService); final NetworkService networkService = new NetworkService(settings); final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool); resourcesToClose.add(clusterService); + final TribeService tribeService = new TribeService(settings, clusterService); + resourcesToClose.add(tribeService); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); ModulesBuilder modules = new ModulesBuilder(); // plugin modules must be added here, before others or we can get crazy injection errors... @@ -253,28 +253,32 @@ public class Node implements Closeable { } final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool); modules.add(new PluginsModule(pluginsService)); - modules.add(new EnvironmentModule(environment, threadPool)); modules.add(new NodeModule(this, monitorService)); modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry)); modules.add(scriptModule); - modules.add(new NodeEnvironmentModule(nodeEnvironment)); modules.add(new DiscoveryModule(this.settings)); modules.add(new ClusterModule(this.settings, clusterService)); modules.add(new IndicesModule(namedWriteableRegistry)); modules.add(new SearchModule(settings, namedWriteableRegistry)); modules.add(new ActionModule(DiscoveryNode.isIngestNode(settings), false)); - modules.add(new GatewayModule(settings)); + modules.add(new GatewayModule()); modules.add(new NodeClientModule()); - modules.add(new ResourceWatcherModule()); modules.add(new RepositoriesModule()); - modules.add(new TribeModule()); modules.add(new AnalysisModule(environment)); pluginsService.processModules(modules); CircuitBreakerService circuitBreakerService = createCircuitBreakerService(settingsModule.getSettings(), settingsModule.getClusterSettings()); resourcesToClose.add(circuitBreakerService); modules.add(settingsModule); - modules.add(b -> b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService)); + modules.add(b -> { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + b.bind(NodeEnvironment.class).toInstance(nodeEnvironment); + b.bind(TribeService.class).toInstance(tribeService); + b.bind(ResourceWatcherService.class).toInstance(resourceWatcherService); + b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService); + } + ); injector = modules.createInjector(); client = injector.getInstance(Client.class); success = true; diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeModule.java b/core/src/main/java/org/elasticsearch/tribe/TribeModule.java deleted file mode 100644 index fb642d1b034..00000000000 --- a/core/src/main/java/org/elasticsearch/tribe/TribeModule.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.tribe; - -import org.elasticsearch.common.inject.AbstractModule; - -/** - */ -public class TribeModule extends AbstractModule { - - @Override - protected void configure() { - bind(TribeService.class).asEagerSingleton(); - } -} diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index 50be6e39b07..259a9d443a3 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -40,7 +40,6 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.regex.Regex; @@ -175,7 +174,6 @@ public class TribeService extends AbstractLifecycleComponent { private final List nodes = new CopyOnWriteArrayList<>(); - @Inject public TribeService(Settings settings, ClusterService clusterService) { super(settings); this.clusterService = clusterService; diff --git a/core/src/main/java/org/elasticsearch/watcher/ResourceWatcherModule.java b/core/src/main/java/org/elasticsearch/watcher/ResourceWatcherModule.java deleted file mode 100644 index a3ae84a954f..00000000000 --- a/core/src/main/java/org/elasticsearch/watcher/ResourceWatcherModule.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.watcher; - -import org.elasticsearch.common.inject.AbstractModule; - -/** - * - */ -public class ResourceWatcherModule extends AbstractModule { - @Override - protected void configure() { - bind(ResourceWatcherService.class).asEagerSingleton(); - } -} diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 65c0a4fddef..d88813203b2 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.InternalSettingsPlugin; @@ -41,9 +40,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; -import static java.util.Collections.singleton; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; @@ -60,7 +57,10 @@ public class NativeScriptTests extends ESTestCase { SettingsModule settingsModule = new SettingsModule(settings, scriptSettings, Collections.emptyList()); final ThreadPool threadPool = new ThreadPool(settings); Injector injector = new ModulesBuilder().add( - new EnvironmentModule(new Environment(settings), threadPool), + (b) -> { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + }, new SettingsModule(settings), scriptModule).createInjector(); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java index 5dd321bdf07..a78c405929a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java @@ -38,7 +38,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.index.query.QueryParseContext; @@ -109,7 +108,11 @@ public class AggregatorParsingTests extends ESTestCase { List> scriptSettings = scriptModule.getSettings(); scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); SettingsModule settingsModule = new SettingsModule(settings, scriptSettings, Collections.emptyList()); - injector = new ModulesBuilder().add(new EnvironmentModule(new Environment(settings), threadPool), settingsModule + injector = new ModulesBuilder().add( + (b) -> { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + }, settingsModule , scriptModule, new IndicesModule(namedWriteableRegistry) { @Override diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index c7d1084067a..b1065c90efa 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -42,7 +42,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.index.query.QueryParseContext; @@ -124,7 +123,10 @@ public abstract class BaseAggregationTestCase { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + }, settingsModule, scriptModule, new IndicesModule(namedWriteableRegistry) { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index a907e75d5f7..0410c5d91d9 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -42,7 +42,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.IndicesModule; @@ -124,7 +123,10 @@ public abstract class BasePipelineAggregationTestCase { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + }, settingsModule, scriptModule, new IndicesModule(namedWriteableRegistry) { diff --git a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java index 3fe1d2a0480..5822372bfa9 100644 --- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java @@ -46,7 +46,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryParseContext; @@ -132,7 +131,10 @@ public class SearchSourceBuilderTests extends ESTestCase { scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); SettingsModule settingsModule = new SettingsModule(settings, scriptSettings, Collections.emptyList()); injector = new ModulesBuilder().add( - new EnvironmentModule(new Environment(settings), threadPool), settingsModule, + (b) -> { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + }, settingsModule, scriptModule, new IndicesModule(namedWriteableRegistry) { @Override protected void configure() { diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java index f0422314c74..60316818a79 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java @@ -38,7 +38,6 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisRegistry; @@ -59,7 +58,6 @@ import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache; import org.elasticsearch.indices.mapper.MapperRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry; -import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.mustache.MustacheScriptEngineService; @@ -110,7 +108,10 @@ public class TemplateQueryParserTests extends ESTestCase { SettingsModule settingsModule = new SettingsModule(settings, scriptSettings, Collections.emptyList()); final ThreadPool threadPool = new ThreadPool(settings); injector = new ModulesBuilder().add( - new EnvironmentModule(new Environment(settings), threadPool), + (b) -> { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + }, settingsModule, new SearchModule(settings, new NamedWriteableRegistry()) { @Override diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java index 319222caa7e..edb062d9e30 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java @@ -76,10 +76,7 @@ public class Ec2DiscoveryTests extends ESTestCase { protected List buildDynamicNodes(Settings nodeSettings, int nodes, List> tagsList) { AwsEc2Service awsEc2Service = new AwsEc2ServiceMock(nodeSettings, nodes, tagsList); - - AwsEc2UnicastHostsProvider provider = new AwsEc2UnicastHostsProvider(nodeSettings, transportService, - awsEc2Service, Version.CURRENT); - + AwsEc2UnicastHostsProvider provider = new AwsEc2UnicastHostsProvider(nodeSettings, transportService, awsEc2Service); List discoveryNodes = provider.buildDynamicNodes(); logger.debug("--> nodes found: {}", discoveryNodes); return discoveryNodes; @@ -231,14 +228,14 @@ public class Ec2DiscoveryTests extends ESTestCase { abstract class DummyEc2HostProvider extends AwsEc2UnicastHostsProvider { public int fetchCount = 0; - public DummyEc2HostProvider(Settings settings, TransportService transportService, AwsEc2Service service, Version version) { - super(settings, transportService, service, version); + public DummyEc2HostProvider(Settings settings, TransportService transportService, AwsEc2Service service) { + super(settings, transportService, service); } } public void testGetNodeListEmptyCache() throws Exception { AwsEc2Service awsEc2Service = new AwsEc2ServiceMock(Settings.EMPTY, 1, null); - DummyEc2HostProvider provider = new DummyEc2HostProvider(Settings.EMPTY, transportService, awsEc2Service, Version.CURRENT) { + DummyEc2HostProvider provider = new DummyEc2HostProvider(Settings.EMPTY, transportService, awsEc2Service) { @Override protected List fetchDynamicNodes() { fetchCount++; @@ -255,7 +252,7 @@ public class Ec2DiscoveryTests extends ESTestCase { Settings.Builder builder = Settings.builder() .put(DISCOVERY_EC2.NODE_CACHE_TIME_SETTING.getKey(), "500ms"); AwsEc2Service awsEc2Service = new AwsEc2ServiceMock(Settings.EMPTY, 1, null); - DummyEc2HostProvider provider = new DummyEc2HostProvider(builder.build(), transportService, awsEc2Service, Version.CURRENT) { + DummyEc2HostProvider provider = new DummyEc2HostProvider(builder.build(), transportService, awsEc2Service) { @Override protected List fetchDynamicNodes() { fetchCount++; diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java index e1041360b1f..07b2ef774b4 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java @@ -78,7 +78,7 @@ public class GceDiscoveryTests extends ESTestCase { @AfterClass public static void stopThreadPool() { - if (threadPool !=null) { + if (threadPool != null) { threadPool.shutdownNow(); threadPool = null; } @@ -111,8 +111,8 @@ public class GceDiscoveryTests extends ESTestCase { } protected List buildDynamicNodes(GceComputeService gceComputeService, Settings nodeSettings) { - GceUnicastHostsProvider provider = new GceUnicastHostsProvider(nodeSettings, gceComputeService, - transportService, new NetworkService(Settings.EMPTY), Version.CURRENT); + GceUnicastHostsProvider provider = new GceUnicastHostsProvider(nodeSettings, gceComputeService, transportService, + new NetworkService(Settings.EMPTY)); List discoveryNodes = provider.buildDynamicNodes(); logger.info("--> nodes found: {}", discoveryNodes); diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index 62a843cee35..65c43fd38c6 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -53,7 +53,6 @@ import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.ModulesBuilder; -import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; @@ -70,7 +69,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisRegistry; @@ -97,15 +95,9 @@ import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.PluginsModule; import org.elasticsearch.plugins.PluginsService; -import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.Script.ScriptParseException; -import org.elasticsearch.script.ScriptContext; -import org.elasticsearch.script.ScriptContextRegistry; -import org.elasticsearch.script.ScriptEngineRegistry; -import org.elasticsearch.script.ScriptEngineService; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.script.ScriptSettings; import org.elasticsearch.search.SearchModule; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.threadpool.ThreadPool; @@ -120,14 +112,11 @@ import java.io.IOException; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; import java.util.concurrent.ExecutionException; import static org.hamcrest.Matchers.containsString; @@ -902,7 +891,10 @@ public abstract class AbstractQueryTestCase> } modulesBuilder.add(new PluginsModule(pluginsService)); modulesBuilder.add( - new EnvironmentModule(new Environment(settings), threadPool), + (b) -> { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + }, settingsModule, new IndicesModule(namedWriteableRegistry) { @Override public void configure() { From 4d78be5b9effff0abc5190ff89562a8e25456eeb Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 05:37:31 -0400 Subject: [PATCH 57/87] remove arity restriction (as def call incorporates all lambdas and all their captures) --- .../java/org/elasticsearch/painless/Def.java | 17 ++++++++++++----- .../elasticsearch/painless/DefBootstrap.java | 6 +++--- .../elasticsearch/painless/node/LDefCall.java | 17 ++++++----------- .../painless/DefBootstrapTests.java | 8 ++++---- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java index a4033255b77..e575ed32183 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java @@ -28,6 +28,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.MethodType; +import java.util.BitSet; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -222,19 +223,25 @@ public final class Def { */ static MethodHandle lookupMethod(Lookup lookup, MethodType callSiteType, Class receiverClass, String name, Object args[]) throws Throwable { - long recipe = (Long) args[0]; + String recipeString = (String) args[0]; int numArguments = callSiteType.parameterCount(); // simple case: no lambdas - if (recipe == 0) { + if (recipeString.isEmpty()) { return lookupMethodInternal(receiverClass, name, numArguments - 1).handle; } + // convert recipe string to a bitset for convenience (the code below should be refactored...) + BitSet lambdaArgs = new BitSet(); + for (int i = 0; i < recipeString.length(); i++) { + lambdaArgs.set(recipeString.charAt(i)); + } + // otherwise: first we have to compute the "real" arity. This is because we have extra arguments: // e.g. f(a, g(x), b, h(y), i()) looks like f(a, g, x, b, h, y, i). int arity = callSiteType.parameterCount() - 1; int upTo = 1; - for (int i = 0; i < numArguments; i++) { - if ((recipe & (1L << (i - 1))) != 0) { + for (int i = 1; i < numArguments; i++) { + if (lambdaArgs.get(i - 1)) { String signature = (String) args[upTo++]; int numCaptures = Integer.parseInt(signature.substring(signature.indexOf(',')+1)); arity -= numCaptures; @@ -250,7 +257,7 @@ public final class Def { upTo = 1; for (int i = 1; i < numArguments; i++) { // its a functional reference, replace the argument with an impl - if ((recipe & (1L << (i - 1))) != 0) { + if (lambdaArgs.get(i - 1)) { // decode signature of form 'type.call,2' String signature = (String) args[upTo++]; int separator = signature.indexOf('.'); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java index a60985eec67..9174911b79c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java @@ -397,11 +397,11 @@ public final class DefBootstrap { if (args.length == 0) { throw new BootstrapMethodError("Invalid number of parameters for method call"); } - if (args[0] instanceof Long == false) { + if (args[0] instanceof String == false) { throw new BootstrapMethodError("Illegal parameter for method call: " + args[0]); } - long recipe = (Long) args[0]; - int numLambdas = Long.bitCount(recipe); + String recipe = (String) args[0]; + int numLambdas = recipe.length(); if (numLambdas > type.parameterCount()) { throw new BootstrapMethodError("Illegal recipe for method call: too many bits"); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java index d216eacae19..4b04cfbf7a5 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefCall.java @@ -41,7 +41,7 @@ final class LDefCall extends ALink implements IDefLink { final String name; final List arguments; - long recipe; + StringBuilder recipe; List pointers = new ArrayList<>(); LDefCall(Location location, String name, List arguments) { @@ -60,14 +60,7 @@ final class LDefCall extends ALink implements IDefLink { @Override ALink analyze(Locals locals) { - if (arguments.size() > 63) { - // technically, the limitation is just methods with > 63 params, containing method references. - // this is because we are lazy and use a long as a bitset. we can always change to a "string" if need be. - // but NEED NOT BE. nothing with this many parameters is in the whitelist and we do not support varargs. - throw new UnsupportedOperationException("methods with > 63 arguments are currently not supported"); - } - - recipe = 0; + recipe = new StringBuilder(); int totalCaptures = 0; for (int argument = 0; argument < arguments.size(); ++argument) { AExpression expression = arguments.get(argument); @@ -78,7 +71,9 @@ final class LDefCall extends ALink implements IDefLink { if (expression instanceof ILambda) { ILambda lambda = (ILambda) expression; pointers.add(lambda.getPointer()); - recipe |= (1L << (argument + totalCaptures)); // mark argument as deferred reference + // encode this parameter as a deferred reference + char ch = (char) (argument + totalCaptures); + recipe.append(ch); totalCaptures += lambda.getCaptureCount(); } @@ -124,7 +119,7 @@ final class LDefCall extends ALink implements IDefLink { List args = new ArrayList<>(); args.add(DefBootstrap.METHOD_CALL); - args.add(recipe); + args.add(recipe.toString()); args.addAll(pointers); writer.invokeDynamic(name, signature.toString(), DEF_BOOTSTRAP_HANDLE, args.toArray()); } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java index 6529bed3a48..8cb065c2611 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java @@ -36,7 +36,7 @@ public class DefBootstrapTests extends ESTestCase { CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), "toString", MethodType.methodType(String.class, Object.class), - DefBootstrap.METHOD_CALL, 0L); + DefBootstrap.METHOD_CALL, ""); MethodHandle handle = site.dynamicInvoker(); assertDepthEquals(site, 0); @@ -53,7 +53,7 @@ public class DefBootstrapTests extends ESTestCase { CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), "toString", MethodType.methodType(String.class, Object.class), - DefBootstrap.METHOD_CALL, 0L); + DefBootstrap.METHOD_CALL, ""); MethodHandle handle = site.dynamicInvoker(); assertDepthEquals(site, 0); @@ -75,7 +75,7 @@ public class DefBootstrapTests extends ESTestCase { CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), "toString", MethodType.methodType(String.class, Object.class), - DefBootstrap.METHOD_CALL, 0L); + DefBootstrap.METHOD_CALL, ""); MethodHandle handle = site.dynamicInvoker(); assertDepthEquals(site, 0); @@ -98,7 +98,7 @@ public class DefBootstrapTests extends ESTestCase { DefBootstrap.PIC site = (DefBootstrap.PIC) DefBootstrap.bootstrap(MethodHandles.publicLookup(), "size", MethodType.methodType(int.class, Object.class), - DefBootstrap.METHOD_CALL, 0L); + DefBootstrap.METHOD_CALL, ""); site.depth = DefBootstrap.PIC.MAX_DEPTH; // mark megamorphic MethodHandle handle = site.dynamicInvoker(); assertEquals(2, (int)handle.invokeExact((Object) Arrays.asList("1", "2"))); From cfa468944515e9568a39cb3a4aa92538cc8fdc3c Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 20 Jun 2016 11:38:48 +0200 Subject: [PATCH 58/87] Share test injector creation --- .../aggregations/BaseAggregationTestCase.java | 104 +++++++++--------- .../BasePipelineAggregationTestCase.java | 78 +------------ 2 files changed, 57 insertions(+), 125 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index b1065c90efa..7bce599f55a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -102,56 +102,9 @@ public abstract class BaseAggregationTestCase> scriptSettings = scriptModule.getSettings(); - scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); - SettingsModule settingsModule = new SettingsModule(settings, scriptSettings, Collections.emptyList()); - injector = new ModulesBuilder().add( - (b) -> { - b.bind(Environment.class).toInstance(new Environment(settings)); - b.bind(ThreadPool.class).toInstance(threadPool); - }, - settingsModule, - scriptModule, - new IndicesModule(namedWriteableRegistry) { - - @Override - protected void configure() { - bindMapperExtension(); - } - }, new SearchModule(settings, namedWriteableRegistry) { - @Override - protected void configureSearch() { - // Skip me - } - }, - new IndexSettingsModule(index, settings), - - new AbstractModule() { - @Override - protected void configure() { - bind(ClusterService.class).toProvider(Providers.of(clusterService)); - bind(CircuitBreakerService.class).to(NoneCircuitBreakerService.class); - bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry); - } - } - ).createInjector(); + injector = buildInjector(index); + namedWriteableRegistry = injector.getInstance(NamedWriteableRegistry.class); aggParsers = injector.getInstance(AggregatorParsers.class); //create some random type with some default field, those types will stick around for all of the subclasses currentTypes = new String[randomIntBetween(0, 5)]; @@ -163,6 +116,59 @@ public abstract class BaseAggregationTestCase> scriptSettings = scriptModule.getSettings(); + scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); + SettingsModule settingsModule = new SettingsModule(settings, scriptSettings, Collections.emptyList()); + return new ModulesBuilder().add( + (b) -> { + b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(ThreadPool.class).toInstance(threadPool); + }, + settingsModule, + scriptModule, + new IndicesModule(namedWriteableRegistry) { + + @Override + protected void configure() { + bindMapperExtension(); + } + }, new SearchModule(settings, namedWriteableRegistry) { + @Override + protected void configureSearch() { + // Skip me + } + }, + new IndexSettingsModule(index, settings), + + new AbstractModule() { + @Override + protected void configure() { + bind(ClusterService.class).toProvider(Providers.of(clusterService)); + bind(CircuitBreakerService.class).to(NoneCircuitBreakerService.class); + bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry); + } + } + ).createInjector(); + } + + @AfterClass public static void afterClass() throws Exception { injector.getInstance(ClusterService.class).close(); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index 0410c5d91d9..a3f9f11dc2e 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -19,54 +19,29 @@ package org.elasticsearch.search.aggregations; -import org.elasticsearch.Version; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Injector; -import org.elasticsearch.common.inject.ModulesBuilder; -import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.settings.Setting; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryParseContext; -import org.elasticsearch.indices.IndicesModule; -import org.elasticsearch.indices.breaker.CircuitBreakerService; -import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.indices.query.IndicesQueriesRegistry; -import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.SearchModule; import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder; -import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexSettingsModule; -import org.elasticsearch.test.InternalSettingsPlugin; -import org.elasticsearch.test.VersionUtils; import org.elasticsearch.threadpool.ThreadPool; import org.junit.AfterClass; import org.junit.BeforeClass; import java.io.IOException; -import java.util.Collections; -import java.util.List; - -import static org.elasticsearch.test.ClusterServiceUtils.createClusterService; -import static org.elasticsearch.test.ClusterServiceUtils.setState; import static org.hamcrest.Matchers.equalTo; public abstract class BasePipelineAggregationTestCase> extends ESTestCase { @@ -76,9 +51,6 @@ public abstract class BasePipelineAggregationTestCase> scriptSettings = scriptModule.getSettings(); - scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); - SettingsModule settingsModule = new SettingsModule(settings, scriptSettings, Collections.emptyList()); - injector = new ModulesBuilder().add( - (b) -> { - b.bind(Environment.class).toInstance(new Environment(settings)); - b.bind(ThreadPool.class).toInstance(threadPool); - }, - settingsModule, - scriptModule, - new IndicesModule(namedWriteableRegistry) { - - @Override - protected void configure() { - bindMapperExtension(); - } - }, new SearchModule(settings, namedWriteableRegistry) { - @Override - protected void configureSearch() { - // Skip me - } - }, - new IndexSettingsModule(index, settings), - new AbstractModule() { - @Override - protected void configure() { - bind(ClusterService.class).toProvider(Providers.of(clusterService)); - bind(CircuitBreakerService.class).to(NoneCircuitBreakerService.class); - bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry); - } - } - ).createInjector(); + injector = BaseAggregationTestCase.buildInjector(index); + namedWriteableRegistry = injector.getInstance(NamedWriteableRegistry.class); aggParsers = injector.getInstance(AggregatorParsers.class); //create some random type with some default field, those types will stick around for all of the subclasses currentTypes = new String[randomIntBetween(0, 5)]; From fb713774a140bd0dfe672694ca69159b8b009909 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 20 Jun 2016 11:45:52 +0200 Subject: [PATCH 59/87] Don't create enviroment more than once --- core/src/main/java/org/elasticsearch/node/Node.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 2069320104a..9c849bbe14b 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -271,7 +271,7 @@ public class Node implements Closeable { resourcesToClose.add(circuitBreakerService); modules.add(settingsModule); modules.add(b -> { - b.bind(Environment.class).toInstance(new Environment(settings)); + b.bind(Environment.class).toInstance(environment); b.bind(ThreadPool.class).toInstance(threadPool); b.bind(NodeEnvironment.class).toInstance(nodeEnvironment); b.bind(TribeService.class).toInstance(tribeService); From e50314bb6ede2fbde462fdcfab2d189cf6e5de63 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 20 Jun 2016 11:53:07 +0200 Subject: [PATCH 60/87] Remove NodeClientModule and PluginsModule --- .../client/node/NodeClientModule.java | 34 ------------------ .../client/transport/TransportClient.java | 11 +++--- .../java/org/elasticsearch/node/Node.java | 7 ++-- .../elasticsearch/plugins/PluginsModule.java | 36 ------------------- .../test/AbstractQueryTestCase.java | 3 +- 5 files changed, 8 insertions(+), 83 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/client/node/NodeClientModule.java delete mode 100644 core/src/main/java/org/elasticsearch/plugins/PluginsModule.java diff --git a/core/src/main/java/org/elasticsearch/client/node/NodeClientModule.java b/core/src/main/java/org/elasticsearch/client/node/NodeClientModule.java deleted file mode 100644 index de134887303..00000000000 --- a/core/src/main/java/org/elasticsearch/client/node/NodeClientModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.client.node; - -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.AbstractModule; - -/** - * - */ -public class NodeClientModule extends AbstractModule { - - @Override - protected void configure() { - bind(Client.class).to(NodeClient.class).asEagerSingleton(); - } -} diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 2c2a5ad0428..09e967b00c4 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -19,7 +19,6 @@ package org.elasticsearch.client.transport; -import org.elasticsearch.Version; import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionModule; @@ -46,7 +45,6 @@ import org.elasticsearch.monitor.MonitorService; import org.elasticsearch.node.Node; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.PluginsModule; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.search.SearchModule; import org.elasticsearch.threadpool.ExecutorBuilder; @@ -120,9 +118,6 @@ public class TransportClient extends AbstractClient { public TransportClient build() { final PluginsService pluginsService = newPluginService(providedSettings); final Settings settings = pluginsService.updatedSettings(); - - Version version = Version.CURRENT; - final ThreadPool threadPool = new ThreadPool(settings); final NetworkService networkService = new NetworkService(settings); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); @@ -133,7 +128,6 @@ public class TransportClient extends AbstractClient { for (Module pluginModule : pluginsService.nodeModules()) { modules.add(pluginModule); } - modules.add(new PluginsModule(pluginsService)); modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry)); modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool)); modules.add(new SearchModule(settings, namedWriteableRegistry) { @@ -156,7 +150,10 @@ public class TransportClient extends AbstractClient { CircuitBreakerService circuitBreakerService = Node.createCircuitBreakerService(settingsModule.getSettings(), settingsModule.getClusterSettings()); modules.add(settingsModule); - modules.add((b -> b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService))); + modules.add((b -> { + b.bind(PluginsService.class).toInstance(pluginsService); + b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService); + })); Injector injector = modules.createInjector(); final TransportService transportService = injector.getInstance(TransportService.class); diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 9c849bbe14b..68073261959 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -27,7 +27,7 @@ import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.Version; import org.elasticsearch.action.ActionModule; import org.elasticsearch.client.Client; -import org.elasticsearch.client.node.NodeClientModule; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateObserver; @@ -87,7 +87,6 @@ import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.node.service.NodeService; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.PluginsModule; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.repositories.RepositoriesModule; @@ -252,7 +251,6 @@ public class Node implements Closeable { modules.add(pluginModule); } final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool); - modules.add(new PluginsModule(pluginsService)); modules.add(new NodeModule(this, monitorService)); modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry)); modules.add(scriptModule); @@ -262,7 +260,6 @@ public class Node implements Closeable { modules.add(new SearchModule(settings, namedWriteableRegistry)); modules.add(new ActionModule(DiscoveryNode.isIngestNode(settings), false)); modules.add(new GatewayModule()); - modules.add(new NodeClientModule()); modules.add(new RepositoriesModule()); modules.add(new AnalysisModule(environment)); pluginsService.processModules(modules); @@ -271,6 +268,8 @@ public class Node implements Closeable { resourcesToClose.add(circuitBreakerService); modules.add(settingsModule); modules.add(b -> { + b.bind(PluginsService.class).toInstance(pluginsService); + b.bind(Client.class).to(NodeClient.class).asEagerSingleton(); b.bind(Environment.class).toInstance(environment); b.bind(ThreadPool.class).toInstance(threadPool); b.bind(NodeEnvironment.class).toInstance(nodeEnvironment); diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsModule.java b/core/src/main/java/org/elasticsearch/plugins/PluginsModule.java deleted file mode 100644 index 04e468cdd6c..00000000000 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsModule.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.plugins; - -import org.elasticsearch.common.inject.AbstractModule; - -public class PluginsModule extends AbstractModule { - - private final PluginsService pluginsService; - - public PluginsModule(PluginsService pluginsService) { - this.pluginsService = pluginsService; - } - - @Override - protected void configure() { - bind(PluginsService.class).toInstance(pluginsService); - } -} diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index 65c43fd38c6..ea2154b355e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -93,7 +93,6 @@ import org.elasticsearch.indices.mapper.MapperRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.PluginsModule; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.script.Script.ScriptParseException; import org.elasticsearch.script.ScriptModule; @@ -889,9 +888,9 @@ public abstract class AbstractQueryTestCase> for (Module pluginModule : pluginsService.nodeModules()) { modulesBuilder.add(pluginModule); } - modulesBuilder.add(new PluginsModule(pluginsService)); modulesBuilder.add( (b) -> { + b.bind(PluginsService.class).toInstance(pluginsService); b.bind(Environment.class).toInstance(new Environment(settings)); b.bind(ThreadPool.class).toInstance(threadPool); }, From 0cb4e574a9c534847ceafcbf83ccebf76cd68123 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 20 Jun 2016 12:16:22 +0200 Subject: [PATCH 61/87] index shard should be able to cancel check index on close. (#18839) If someone sets `index.shard.check_on_startup`, indexing start up time can be slow (by design, it diligently goes and checks all data). If for some reason the shard is closed in that time, the store ref is kept around and prevents a new shard copy to be allocated to this node via the shard level locks. This is especially tricky if the shard is close due to a cancelled recovery which may re-restart soon. This commit adds a cancellable threads instance to each IndexShard and perform index checking underneath it, so it can be cancelled on close. --- .../java/org/elasticsearch/index/shard/IndexShard.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 26701703ce1..9ebbde77c6a 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -53,6 +53,7 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.Callback; +import org.elasticsearch.common.util.CancellableThreads; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.SuspendableRefContainer; import org.elasticsearch.index.Index; @@ -131,8 +132,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.stream.Collectors; public class IndexShard extends AbstractIndexShardComponent implements IndicesClusterStateService.Shard { @@ -158,6 +159,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl private final TranslogConfig translogConfig; private final IndexEventListener indexEventListener; private final QueryCachingPolicy cachingPolicy; + private final CancellableThreads cancellableThreads; /** @@ -265,6 +267,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl primaryTerm = indexSettings.getIndexMetaData().primaryTerm(shardId.id()); refreshListeners = buildRefreshListeners(); persistMetadata(shardRouting, null); + cancellableThreads = new CancellableThreads(); } public Store store() { @@ -843,6 +846,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl } finally { // playing safe here and close the engine even if the above succeeds - close can be called multiple times IOUtils.close(engine); } + cancellableThreads.cancel(reason); } } } @@ -1281,7 +1285,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl private void checkIndex() throws IOException { if (store.tryIncRef()) { try { - doCheckIndex(); + cancellableThreads.executeIO(this::doCheckIndex); } finally { store.decRef(); } From 9506f605046c8aa05b2fd57cd430f207a4334a78 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 20 Jun 2016 13:10:35 +0200 Subject: [PATCH 62/87] Improve error message if a setting is not found (#18920) Today we only emit that the setting wasn't found unless we have some DYM suggestions. Yet, if a setting is not found at all and there are no suggestions due to typos it's likely a removed setting or the plugin that is supposed to be configured is not installed. This commit adds some info text to the exception to help the user debugging the problem before opening bugreports. Instead of emitting: `unknown setting [foo.bar]` we now emit: `unknown setting [foo.bar] please check the migration guide for removed settings and ensure that the plugin you are configuring is installed` Relates to #18663 --- .../resources/checkstyle_suppressions.xml | 2 -- .../settings/AbstractScopedSettings.java | 3 +++ .../admin/indices/create/CreateIndexIT.java | 26 ++++++++++++------- .../common/settings/ScopedSettingsTests.java | 6 +++-- .../common/settings/SettingsModuleTests.java | 6 +++-- .../indices/state/SimpleIndexStateIT.java | 12 ++++++--- .../template/SimpleIndexTemplateIT.java | 3 ++- 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index ffad8d37c5b..27b9efbf0a4 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -712,7 +712,6 @@ - @@ -1022,7 +1021,6 @@ - diff --git a/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java b/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java index 0170c4218a2..817e109bf4d 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java @@ -263,6 +263,9 @@ public abstract class AbstractScopedSettings extends AbstractComponent { List keys = scoredKeys.stream().map((a) -> a.v2()).collect(Collectors.toList()); if (keys.isEmpty() == false) { msg += " did you mean " + (keys.size() == 1 ? "[" + keys.get(0) + "]": "any of " + keys.toString()) + "?"; + } else { + msg += " please check that any required plugins are installed, or check the breaking changes documentation for removed " + + "settings"; } throw new IllegalArgumentException(msg); } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java index 8fbb489d9c2..3e7323dceeb 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java @@ -70,7 +70,8 @@ public class CreateIndexIT extends ESIntegTestCase { prepareCreate("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 4L)).get(); fail(); } catch (IllegalArgumentException ex) { - assertEquals("unknown setting [index.creation_date]", ex.getMessage()); + assertEquals("unknown setting [index.creation_date] please check that any required plugins are installed, or check the " + + "breaking changes documentation for removed settings", ex.getMessage()); } } @@ -165,7 +166,8 @@ public class CreateIndexIT extends ESIntegTestCase { .get(); fail("should have thrown an exception about the shard count"); } catch (IllegalArgumentException e) { - assertEquals("unknown setting [index.unknown.value]", e.getMessage()); + assertEquals("unknown setting [index.unknown.value] please check that any required plugins are installed, or check the" + + " breaking changes documentation for removed settings", e.getMessage()); } } @@ -211,13 +213,16 @@ public class CreateIndexIT extends ESIntegTestCase { @Override public void run() { try { - client().prepareIndex("test", "test").setSource("index_version", indexVersion.get()).get(); // recreate that index + // recreate that index + client().prepareIndex("test", "test").setSource("index_version", indexVersion.get()).get(); synchronized (indexVersionLock) { - // we sync here since we have to ensure that all indexing operations below for a given ID are done before we increment the - // index version otherwise a doc that is in-flight could make it into an index that it was supposed to be deleted for and our assertion fail... + // we sync here since we have to ensure that all indexing operations below for a given ID are done before + // we increment the index version otherwise a doc that is in-flight could make it into an index that it + // was supposed to be deleted for and our assertion fail... indexVersion.incrementAndGet(); } - assertAcked(client().admin().indices().prepareDelete("test").get()); // from here on all docs with index_version == 0|1 must be gone!!!! only 2 are ok; + // from here on all docs with index_version == 0|1 must be gone!!!! only 2 are ok; + assertAcked(client().admin().indices().prepareDelete("test").get()); } finally { latch.countDown(); } @@ -249,8 +254,10 @@ public class CreateIndexIT extends ESIntegTestCase { latch.await(); refresh(); - // we only really assert that we never reuse segments of old indices or anything like this here and that nothing fails with crazy exceptions - SearchResponse expected = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).setQuery(new RangeQueryBuilder("index_version").from(indexVersion.get(), true)).get(); + // we only really assert that we never reuse segments of old indices or anything like this here and that nothing fails with + // crazy exceptions + SearchResponse expected = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()) + .setQuery(new RangeQueryBuilder("index_version").from(indexVersion.get(), true)).get(); SearchResponse all = client().prepareSearch("test").setIndicesOptions(IndicesOptions.lenientExpandOpen()).get(); assertEquals(expected + " vs. " + all, expected.getHits().getTotalHits(), all.getHits().getTotalHits()); logger.info("total: {}", expected.getHits().getTotalHits()); @@ -283,7 +290,8 @@ public class CreateIndexIT extends ESIntegTestCase { } public void testRestartIndexCreationAfterFullClusterRestart() throws Exception { - client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put("cluster.routing.allocation.enable", "none")).get(); + client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put("cluster.routing.allocation.enable", + "none")).get(); client().admin().indices().prepareCreate("test").setSettings(indexSettings()).get(); internalCluster().fullRestart(); ensureGreen("test"); diff --git a/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java b/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java index 3afd60d86e4..664f8cb96ab 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java @@ -202,20 +202,22 @@ public class ScopedSettingsTests extends ESTestCase { IndexScopedSettings settings = new IndexScopedSettings( Settings.EMPTY, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); + String unknownMsgSuffix = " please check that any required plugins are installed, or check the breaking changes documentation for" + + " removed settings"; settings.validate(Settings.builder().put("index.store.type", "boom")); settings.validate(Settings.builder().put("index.store.type", "boom").build()); try { settings.validate(Settings.builder().put("index.store.type", "boom", "i.am.not.a.setting", true)); fail(); } catch (IllegalArgumentException e) { - assertEquals("unknown setting [i.am.not.a.setting]", e.getMessage()); + assertEquals("unknown setting [i.am.not.a.setting]" + unknownMsgSuffix, e.getMessage()); } try { settings.validate(Settings.builder().put("index.store.type", "boom", "i.am.not.a.setting", true).build()); fail(); } catch (IllegalArgumentException e) { - assertEquals("unknown setting [i.am.not.a.setting]", e.getMessage()); + assertEquals("unknown setting [i.am.not.a.setting]" + unknownMsgSuffix, e.getMessage()); } try { diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java index 353b7b61d6c..692134916ef 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java @@ -51,7 +51,8 @@ public class SettingsModuleTests extends ModuleTestCase { () -> new SettingsModule(settings)); assertEquals("Failed to parse value [[2.0]] for setting [cluster.routing.allocation.balance.shard]", ex.getMessage()); assertEquals(1, ex.getSuppressed().length); - assertEquals("unknown setting [some.foo.bar]", ex.getSuppressed()[0].getMessage()); + assertEquals("unknown setting [some.foo.bar] please check that any required plugins are installed, or check the breaking " + + "changes documentation for removed settings", ex.getSuppressed()[0].getMessage()); } { @@ -127,7 +128,8 @@ public class SettingsModuleTests extends ModuleTestCase { new SettingsModule(settings); fail(); } catch (IllegalArgumentException ex) { - assertEquals("tribe.blocks validation failed: unknown setting [wtf]", ex.getMessage()); + assertEquals("tribe.blocks validation failed: unknown setting [wtf] please check that any required plugins are" + + " installed, or check the breaking changes documentation for removed settings", ex.getMessage()); } } } diff --git a/core/src/test/java/org/elasticsearch/indices/state/SimpleIndexStateIT.java b/core/src/test/java/org/elasticsearch/indices/state/SimpleIndexStateIT.java index f3898bc9f3c..ea3ebf5179b 100644 --- a/core/src/test/java/org/elasticsearch/indices/state/SimpleIndexStateIT.java +++ b/core/src/test/java/org/elasticsearch/indices/state/SimpleIndexStateIT.java @@ -56,7 +56,8 @@ public class SimpleIndexStateIT extends ESIntegTestCase { ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get(); assertThat(stateResponse.getState().metaData().index("test").getState(), equalTo(IndexMetaData.State.OPEN)); assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(numShards.numPrimaries)); - assertThat(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), equalTo(numShards.totalNumShards)); + assertEquals(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size() + , numShards.totalNumShards); logger.info("--> indexing a simple document"); client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get(); @@ -88,7 +89,8 @@ public class SimpleIndexStateIT extends ESIntegTestCase { assertThat(stateResponse.getState().metaData().index("test").getState(), equalTo(IndexMetaData.State.OPEN)); assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(numShards.numPrimaries)); - assertThat(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), equalTo(numShards.totalNumShards)); + assertEquals(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), + numShards.totalNumShards); logger.info("--> indexing a simple document"); client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get(); @@ -119,7 +121,8 @@ public class SimpleIndexStateIT extends ESIntegTestCase { ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get(); assertThat(stateResponse.getState().metaData().index("test").getState(), equalTo(IndexMetaData.State.OPEN)); assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(numShards.numPrimaries)); - assertThat(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), equalTo(numShards.totalNumShards)); + assertEquals(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), + numShards.totalNumShards); logger.info("--> indexing a simple document"); client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get(); @@ -143,7 +146,8 @@ public class SimpleIndexStateIT extends ESIntegTestCase { } logger.info("--> creating test index with valid settings "); - CreateIndexResponse response = client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("number_of_shards", 1)).get(); + CreateIndexResponse response = client().admin().indices().prepareCreate("test") + .setSettings(Settings.builder().put("number_of_shards", 1)).get(); assertThat(response.isAcknowledged(), equalTo(true)); } } diff --git a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java index 298cb9cd9e3..493f8b74e04 100644 --- a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java +++ b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java @@ -322,7 +322,8 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase { .setTemplate("te*") .setSettings(Settings.builder().put("does_not_exist", "test")) .get()); - assertEquals("unknown setting [index.does_not_exist]", e.getMessage()); + assertEquals("unknown setting [index.does_not_exist] please check that any required plugins are" + + " installed, or check the breaking changes documentation for removed settings", e.getMessage()); response = client().admin().indices().prepareGetTemplates().get(); assertEquals(0, response.getIndexTemplates().size()); From 459665914b3aa3b107a3e3c9069ab812ebbf36b7 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 20 Jun 2016 13:18:19 +0200 Subject: [PATCH 63/87] Detach BigArrays from Guice (#18973) BigArrays can be fully constructed without Guice, this change cleans up it's creation and the mocking in MockNode. --- .../client/transport/TransportClient.java | 39 ++++++++----------- .../TransportClientNodesService.java | 3 +- .../elasticsearch/common/util/BigArrays.java | 3 +- .../elasticsearch/env/NodeEnvironment.java | 5 --- .../java/org/elasticsearch/node/Node.java | 11 ++++++ .../org/elasticsearch/node/NodeModule.java | 9 ----- .../common/util/MockBigArrays.java | 1 - .../java/org/elasticsearch/node/MockNode.java | 14 ++++++- .../elasticsearch/node/NodeMocksPlugin.java | 7 +--- .../test/InternalTestCluster.java | 9 +++-- .../test/NodeConfigurationSource.java | 8 ---- 11 files changed, 51 insertions(+), 58 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 09e967b00c4..f36fd199292 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -19,6 +19,7 @@ package org.elasticsearch.client.transport; +import org.apache.lucene.util.IOUtils; import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionModule; @@ -41,7 +42,6 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.indices.breaker.CircuitBreakerService; -import org.elasticsearch.monitor.MonitorService; import org.elasticsearch.node.Node; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.Plugin; @@ -52,6 +52,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.netty.NettyTransport; +import java.io.Closeable; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -118,10 +119,11 @@ public class TransportClient extends AbstractClient { public TransportClient build() { final PluginsService pluginsService = newPluginService(providedSettings); final Settings settings = pluginsService.updatedSettings(); + final List resourcesToClose = new ArrayList<>(); final ThreadPool threadPool = new ThreadPool(settings); + resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS)); final NetworkService networkService = new NetworkService(settings); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); - boolean success = false; try { ModulesBuilder modules = new ModulesBuilder(); // plugin modules must be added here, before others or we can get crazy injection errors... @@ -149,8 +151,12 @@ public class TransportClient extends AbstractClient { SettingsModule settingsModule = new SettingsModule(settings, additionalSettings, additionalSettingsFilter); CircuitBreakerService circuitBreakerService = Node.createCircuitBreakerService(settingsModule.getSettings(), settingsModule.getClusterSettings()); + resourcesToClose.add(circuitBreakerService); + BigArrays bigArrays = new BigArrays(settings, circuitBreakerService); + resourcesToClose.add(bigArrays); modules.add(settingsModule); modules.add((b -> { + b.bind(BigArrays.class).toInstance(bigArrays); b.bind(PluginsService.class).toInstance(pluginsService); b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService); })); @@ -159,14 +165,11 @@ public class TransportClient extends AbstractClient { final TransportService transportService = injector.getInstance(TransportService.class); transportService.start(); transportService.acceptIncomingRequests(); - TransportClient transportClient = new TransportClient(injector); - success = true; + resourcesToClose.clear(); return transportClient; } finally { - if (!success) { - ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS); - } + IOUtils.closeWhileHandlingException(resourcesToClose); } } } @@ -261,24 +264,16 @@ public class TransportClient extends AbstractClient { */ @Override public void close() { - injector.getInstance(TransportClientNodesService.class).close(); - injector.getInstance(TransportService.class).close(); - try { - injector.getInstance(MonitorService.class).close(); - } catch (Exception e) { - // ignore, might not be bounded - } + List closeables = new ArrayList<>(); + closeables.add(injector.getInstance(TransportClientNodesService.class)); + closeables.add(injector.getInstance(TransportService.class)); for (Class plugin : injector.getInstance(PluginsService.class).nodeServices()) { - injector.getInstance(plugin).close(); + closeables.add(injector.getInstance(plugin)); } - try { - ThreadPool.terminate(injector.getInstance(ThreadPool.class), 10, TimeUnit.SECONDS); - } catch (Exception e) { - // ignore - } - - injector.getInstance(BigArrays.class).close(); + closeables.add(() -> ThreadPool.terminate(injector.getInstance(ThreadPool.class), 10, TimeUnit.SECONDS)); + closeables.add(injector.getInstance(BigArrays.class)); + IOUtils.closeWhileHandlingException(closeables); } @Override diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java index 0781576524d..120a4711217 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java @@ -48,6 +48,7 @@ import org.elasticsearch.transport.TransportException; import org.elasticsearch.transport.TransportRequestOptions; import org.elasticsearch.transport.TransportService; +import java.io.Closeable; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -66,7 +67,7 @@ import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; /** * */ -public class TransportClientNodesService extends AbstractComponent { +public class TransportClientNodesService extends AbstractComponent implements Closeable { private final TimeValue nodesSamplerInterval; diff --git a/core/src/main/java/org/elasticsearch/common/util/BigArrays.java b/core/src/main/java/org/elasticsearch/common/util/BigArrays.java index 017881a9218..c2c8e242acc 100644 --- a/core/src/main/java/org/elasticsearch/common/util/BigArrays.java +++ b/core/src/main/java/org/elasticsearch/common/util/BigArrays.java @@ -373,12 +373,11 @@ public class BigArrays implements Releasable { final boolean checkBreaker; private final BigArrays circuitBreakingInstance; - @Inject public BigArrays(Settings settings, @Nullable final CircuitBreakerService breakerService) { // Checking the breaker is disabled if not specified this(new PageCacheRecycler(settings), breakerService, false); } - + // public for tests public BigArrays(PageCacheRecycler recycler, @Nullable final CircuitBreakerService breakerService, boolean checkBreaker) { this.checkBreaker = checkBreaker; this.recycler = recycler; diff --git a/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 2b2aab2ccd2..8815d18769d 100644 --- a/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -32,12 +32,9 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.SuppressForbidden; -import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; @@ -66,7 +63,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -167,7 +163,6 @@ public final class NodeEnvironment extends AbstractComponent implements Closeabl public static final String NODE_LOCK_FILENAME = "node.lock"; public static final String UPGRADE_LOCK_FILENAME = "upgrade.lock"; - @Inject public NodeEnvironment(Settings settings, Environment environment) throws IOException { super(settings); diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 68073261959..de77f02ef51 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -266,6 +266,8 @@ public class Node implements Closeable { CircuitBreakerService circuitBreakerService = createCircuitBreakerService(settingsModule.getSettings(), settingsModule.getClusterSettings()); resourcesToClose.add(circuitBreakerService); + BigArrays bigArrays = createBigArrays(settings, circuitBreakerService); + resourcesToClose.add(bigArrays); modules.add(settingsModule); modules.add(b -> { b.bind(PluginsService.class).toInstance(pluginsService); @@ -276,6 +278,7 @@ public class Node implements Closeable { b.bind(TribeService.class).toInstance(tribeService); b.bind(ResourceWatcherService.class).toInstance(resourceWatcherService); b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService); + b.bind(BigArrays.class).toInstance(bigArrays); } ); injector = modules.createInjector(); @@ -626,4 +629,12 @@ public class Node implements Closeable { throw new IllegalArgumentException("Unknown circuit breaker type [" + type + "]"); } } + + /** + * Creates a new {@link BigArrays} instance used for this node. + * This method can be overwritten by subclasses to change their {@link BigArrays} implementation for instance for testing + */ + BigArrays createBigArrays(Settings settings, CircuitBreakerService circuitBreakerService) { + return new BigArrays(settings, circuitBreakerService); + } } diff --git a/core/src/main/java/org/elasticsearch/node/NodeModule.java b/core/src/main/java/org/elasticsearch/node/NodeModule.java index c5d087c0ef2..85cfe5bd6b2 100644 --- a/core/src/main/java/org/elasticsearch/node/NodeModule.java +++ b/core/src/main/java/org/elasticsearch/node/NodeModule.java @@ -37,9 +37,6 @@ public class NodeModule extends AbstractModule { private final MonitorService monitorService; private final ProcessorsRegistry.Builder processorsRegistryBuilder; - // pkg private so tests can mock - Class bigArraysImpl = BigArrays.class; - public NodeModule(Node node, MonitorService monitorService) { this.node = node; this.monitorService = monitorService; @@ -48,12 +45,6 @@ public class NodeModule extends AbstractModule { @Override protected void configure() { - if (bigArraysImpl == BigArrays.class) { - bind(BigArrays.class).asEagerSingleton(); - } else { - bind(BigArrays.class).to(bigArraysImpl).asEagerSingleton(); - } - bind(Node.class).toInstance(node); bind(MonitorService.class).toInstance(monitorService); bind(NodeService.class).asEagerSingleton(); diff --git a/test/framework/src/main/java/org/elasticsearch/common/util/MockBigArrays.java b/test/framework/src/main/java/org/elasticsearch/common/util/MockBigArrays.java index 26e021bf031..613445c2271 100644 --- a/test/framework/src/main/java/org/elasticsearch/common/util/MockBigArrays.java +++ b/test/framework/src/main/java/org/elasticsearch/common/util/MockBigArrays.java @@ -74,7 +74,6 @@ public class MockBigArrays extends BigArrays { private final PageCacheRecycler recycler; private final CircuitBreakerService breakerService; - @Inject public MockBigArrays(Settings settings, CircuitBreakerService breakerService) { this(new MockPageCacheRecycler(settings), breakerService, false); } diff --git a/test/framework/src/main/java/org/elasticsearch/node/MockNode.java b/test/framework/src/main/java/org/elasticsearch/node/MockNode.java index 749f1f3279e..33077d5ffbd 100644 --- a/test/framework/src/main/java/org/elasticsearch/node/MockNode.java +++ b/test/framework/src/main/java/org/elasticsearch/node/MockNode.java @@ -19,8 +19,10 @@ package org.elasticsearch.node; -import org.elasticsearch.Version; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.MockBigArrays; +import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.Plugin; @@ -35,15 +37,25 @@ import java.util.Collection; */ public class MockNode extends Node { + private final boolean mockBigArrays; private Collection> plugins; public MockNode(Settings settings, Collection> classpathPlugins) { super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins); this.plugins = classpathPlugins; + this.mockBigArrays = classpathPlugins.contains(NodeMocksPlugin.class); // if this plugin is present we mock bigarrays :) } public Collection> getPlugins() { return plugins; } + @Override + protected BigArrays createBigArrays(Settings settings, CircuitBreakerService circuitBreakerService) { + if (mockBigArrays) { + return new MockBigArrays(settings, circuitBreakerService); + } else { + return super.createBigArrays(settings, circuitBreakerService); + } + } } diff --git a/test/framework/src/main/java/org/elasticsearch/node/NodeMocksPlugin.java b/test/framework/src/main/java/org/elasticsearch/node/NodeMocksPlugin.java index a121ad46bcc..2ca1ac7804d 100644 --- a/test/framework/src/main/java/org/elasticsearch/node/NodeMocksPlugin.java +++ b/test/framework/src/main/java/org/elasticsearch/node/NodeMocksPlugin.java @@ -18,12 +18,7 @@ */ package org.elasticsearch.node; -import org.elasticsearch.common.util.MockBigArrays; import org.elasticsearch.plugins.Plugin; -public class NodeMocksPlugin extends Plugin { - - public void onModule(NodeModule module) { - module.bigArraysImpl = MockBigArrays.class; - } +public class NodeMocksPlugin extends Plugin { // just a marker plugin for MockNode to mock out BigArrays } diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 950653cba5e..025740dbe36 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -902,9 +902,12 @@ public final class InternalTestCluster extends TestCluster { @Override public void close() throws IOException { - resetClient(); - closed.set(true); - closeNode(); + try { + resetClient(); + } finally { + closed.set(true); + closeNode(); + } } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/NodeConfigurationSource.java b/test/framework/src/main/java/org/elasticsearch/test/NodeConfigurationSource.java index c54a00b174d..e04e840e525 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/NodeConfigurationSource.java +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeConfigurationSource.java @@ -19,18 +19,10 @@ package org.elasticsearch.test; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.MockEngineFactoryPlugin; -import org.elasticsearch.node.NodeMocksPlugin; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.search.MockSearchService; -import org.elasticsearch.test.store.MockFSIndexStore; -import org.elasticsearch.test.transport.AssertingLocalTransport; -import org.elasticsearch.test.transport.MockTransportService; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.List; public abstract class NodeConfigurationSource { From 93415d45061ca35042c21c45a1593cca39adb8d1 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 15 Jun 2016 09:07:18 +0200 Subject: [PATCH 64/87] Expose MMapDirectory.preLoad(). #18880 The MMapDirectory has a switch that allows the content of files to be loaded into the filesystem cache upon opening. This commit exposes it with the new `index.store.pre_load` setting. --- .../common/settings/IndexScopedSettings.java | 1 + .../org/elasticsearch/index/IndexModule.java | 9 +++ .../index/store/FsDirectoryService.java | 58 +++++++------- .../index/store/FsDirectoryServiceTests.java | 44 ++++++++++- .../index/store/IndexStoreTests.java | 14 +--- docs/reference/index-modules/store.asciidoc | 79 ++++++++++++++++--- 6 files changed, 148 insertions(+), 57 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index fb60453d467..bbbbe57618b 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -134,6 +134,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings { MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING, BitsetFilterCache.INDEX_LOAD_RANDOM_ACCESS_FILTERS_EAGERLY_SETTING, IndexModule.INDEX_STORE_TYPE_SETTING, + IndexModule.INDEX_STORE_PRE_LOAD_SETTING, IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING, IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING, PrimaryShardAllocator.INDEX_RECOVERY_INITIAL_SHARDS_SETTING, diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java index 6ceabd1146d..d233faf4f19 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexModule.java +++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java @@ -45,6 +45,7 @@ import org.elasticsearch.indices.mapper.MapperRegistry; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -74,6 +75,14 @@ public final class IndexModule { public static final Setting INDEX_STORE_TYPE_SETTING = new Setting<>("index.store.type", "", Function.identity(), Property.IndexScope, Property.NodeScope); + + /** On which extensions to load data into the file-system cache upon opening of files. + * This only works with the mmap directory, and even in that case is still + * best-effort only. */ + public static final Setting> INDEX_STORE_PRE_LOAD_SETTING = + Setting.listSetting("index.store.preload", Collections.emptyList(), Function.identity(), + Property.IndexScope, Property.NodeScope); + public static final String SIMILARITY_SETTINGS_PREFIX = "index.similarity"; // whether to use the query cache diff --git a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java index 5ad5c232f2e..69eedd7ef19 100644 --- a/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java +++ b/core/src/main/java/org/elasticsearch/index/store/FsDirectoryService.java @@ -31,13 +31,11 @@ import org.apache.lucene.store.SimpleFSDirectory; import org.apache.lucene.store.SimpleFSLockFactory; import org.apache.lucene.store.SleepingLockWrapper; import org.apache.lucene.store.StoreRateLimiting; -import org.apache.lucene.util.Constants; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; -import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardPath; @@ -45,7 +43,7 @@ import org.elasticsearch.index.shard.ShardPath; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collections; +import java.util.HashSet; import java.util.Set; /** @@ -87,8 +85,12 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim @Override public Directory newDirectory() throws IOException { final Path location = path.resolveIndex(); + final LockFactory lockFactory = indexSettings.getValue(INDEX_LOCK_FACTOR_SETTING); Files.createDirectories(location); - Directory wrapped = newFSDirectory(location, indexSettings.getValue(INDEX_LOCK_FACTOR_SETTING)); + Directory wrapped = newFSDirectory(location, lockFactory); + Set preLoadExtensions = new HashSet<>( + indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING)); + wrapped = setPreload(wrapped, location, lockFactory, preLoadExtensions); if (IndexMetaData.isOnSharedFilesystem(indexSettings.getSettings())) { wrapped = new SleepingLockWrapper(wrapped, 5000); } @@ -100,25 +102,11 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim rateLimitingTimeInNanos.inc(nanos); } - /* - * We are mmapping norms, docvalues as well as term dictionaries, all other files are served through NIOFS - * this provides good random access performance while not creating unnecessary mmaps for files like stored - * fields etc. - */ - private static final Set PRIMARY_EXTENSIONS = Collections.unmodifiableSet(Sets.newHashSet("nvd", "dvd", "tim")); - - protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException { final String storeType = indexSettings.getSettings().get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), IndexModule.Type.FS.getSettingsKey()); - if (IndexModule.Type.FS.match(storeType) || isDefault(storeType)) { - final FSDirectory open = FSDirectory.open(location, lockFactory); // use lucene defaults - if (open instanceof MMapDirectory - && isDefault(storeType) - && Constants.WINDOWS == false) { - return newDefaultDir(location, (MMapDirectory) open, lockFactory); - } - return open; + if (IndexModule.Type.FS.match(storeType) || IndexModule.Type.DEFAULT.match(storeType)) { + return FSDirectory.open(location, lockFactory); // use lucene defaults } else if (IndexModule.Type.SIMPLEFS.match(storeType)) { return new SimpleFSDirectory(location, lockFactory); } else if (IndexModule.Type.NIOFS.match(storeType)) { @@ -129,17 +117,25 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim throw new IllegalArgumentException("No directory found for type [" + storeType + "]"); } - private static boolean isDefault(String storeType) { - return IndexModule.Type.DEFAULT.match(storeType); - } - - private Directory newDefaultDir(Path location, final MMapDirectory mmapDir, LockFactory lockFactory) throws IOException { - return new FileSwitchDirectory(PRIMARY_EXTENSIONS, mmapDir, new NIOFSDirectory(location, lockFactory), true) { - @Override - public String[] listAll() throws IOException { - // Avoid doing listAll twice: - return mmapDir.listAll(); + private static Directory setPreload(Directory directory, Path location, LockFactory lockFactory, + Set preLoadExtensions) throws IOException { + if (preLoadExtensions.isEmpty() == false + && directory instanceof MMapDirectory + && ((MMapDirectory) directory).getPreload() == false) { + if (preLoadExtensions.contains("*")) { + ((MMapDirectory) directory).setPreload(true); + return directory; } - }; + MMapDirectory primary = new MMapDirectory(location, lockFactory); + primary.setPreload(true); + return new FileSwitchDirectory(preLoadExtensions, primary, directory, true) { + @Override + public String[] listAll() throws IOException { + // avoid listing twice + return primary.listAll(); + } + }; + } + return directory; } } diff --git a/core/src/test/java/org/elasticsearch/index/store/FsDirectoryServiceTests.java b/core/src/test/java/org/elasticsearch/index/store/FsDirectoryServiceTests.java index f7d793f03ed..6042d471717 100644 --- a/core/src/test/java/org/elasticsearch/index/store/FsDirectoryServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/store/FsDirectoryServiceTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.index.store; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.FilterDirectory; +import org.apache.lucene.store.FileSwitchDirectory; +import org.apache.lucene.store.MMapDirectory; import org.apache.lucene.store.RateLimitedFSDirectory; import org.apache.lucene.store.SimpleFSDirectory; import org.apache.lucene.store.SleepingLockWrapper; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.ShardId; @@ -36,6 +36,7 @@ import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; public class FsDirectoryServiceTests extends ESTestCase { @@ -73,4 +74,43 @@ public class FsDirectoryServiceTests extends ESTestCase { assertFalse(delegate instanceof SleepingLockWrapper); assertTrue(delegate instanceof SimpleFSDirectory); } + + public void testPreload() throws IOException { + doTestPreload(); + doTestPreload("nvd", "dvd", "tim"); + doTestPreload("*"); + } + + private void doTestPreload(String...preload) throws IOException { + Settings build = Settings.builder() + .put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "mmapfs") + .putArray(IndexModule.INDEX_STORE_PRE_LOAD_SETTING.getKey(), preload) + .build(); + IndexSettings settings = IndexSettingsModule.newIndexSettings("foo", build); + IndexStoreConfig config = new IndexStoreConfig(settings.getSettings()); + IndexStore store = new IndexStore(settings, config); + Path tempDir = createTempDir().resolve(settings.getUUID()).resolve("0"); + Files.createDirectories(tempDir); + ShardPath path = new ShardPath(false, tempDir, tempDir, new ShardId(settings.getIndex(), 0)); + FsDirectoryService fsDirectoryService = new FsDirectoryService(settings, store, path); + Directory directory = fsDirectoryService.newDirectory(); + assertTrue(directory instanceof RateLimitedFSDirectory); + RateLimitedFSDirectory rateLimitingDirectory = (RateLimitedFSDirectory) directory; + Directory delegate = rateLimitingDirectory.getDelegate(); + assertFalse(delegate instanceof SleepingLockWrapper); + if (preload.length == 0) { + assertTrue(delegate.toString(), delegate instanceof MMapDirectory); + assertFalse(((MMapDirectory) delegate).getPreload()); + } else if (Arrays.asList(preload).contains("*")) { + assertTrue(delegate.toString(), delegate instanceof MMapDirectory); + assertTrue(((MMapDirectory) delegate).getPreload()); + } else { + assertTrue(delegate.toString(), delegate instanceof FileSwitchDirectory); + FileSwitchDirectory fsd = (FileSwitchDirectory) delegate; + assertTrue(fsd.getPrimaryDir() instanceof MMapDirectory); + assertTrue(((MMapDirectory) fsd.getPrimaryDir()).getPreload()); + assertTrue(fsd.getSecondaryDir() instanceof MMapDirectory); + assertFalse(((MMapDirectory) fsd.getSecondaryDir()).getPreload()); + } + } } diff --git a/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java b/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java index 0e012f0d1a7..fe5410ccaf8 100644 --- a/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java +++ b/core/src/test/java/org/elasticsearch/index/store/IndexStoreTests.java @@ -77,6 +77,7 @@ public class IndexStoreTests extends ESTestCase { assertTrue(type + " " + directory.toString(), directory instanceof SimpleFSDirectory); break; case FS: + case DEFAULT: if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { assertTrue(directory.toString(), directory instanceof MMapDirectory); } else if (Constants.WINDOWS) { @@ -85,19 +86,6 @@ public class IndexStoreTests extends ESTestCase { assertTrue(directory.toString(), directory instanceof NIOFSDirectory); } break; - case DEFAULT: - if (Constants.WINDOWS) { - if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { - assertTrue(type + " " + directory.toString(), directory instanceof MMapDirectory); - } else { - assertTrue(type + " " + directory.toString(), directory instanceof SimpleFSDirectory); - } - } else if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { - assertTrue(type + " " + directory.toString(), directory instanceof FileSwitchDirectory); - } else { - assertTrue(type + " " + directory.toString(), directory instanceof NIOFSDirectory); - } - break; default: fail(); } diff --git a/docs/reference/index-modules/store.asciidoc b/docs/reference/index-modules/store.asciidoc index 54080e365c2..ee7fd8766fd 100644 --- a/docs/reference/index-modules/store.asciidoc +++ b/docs/reference/index-modules/store.asciidoc @@ -7,9 +7,9 @@ The store module allows you to control how index data is stored and accessed on [[file-system]] === File system storage types -There are different file system implementations or _storage types_. The best -one for the operating environment will be automatically chosen: `simplefs` on -Windows 32bit, `niofs` on other 32bit systems and `mmapfs` on 64bit systems. +There are different file system implementations or _storage types_. By default, +elasticsearch will pick the best implementation based on the operating +environment. This can be overridden for all indices by adding this to the `config/elasticsearch.yml` file: @@ -36,6 +36,12 @@ experimental[This is an expert-only setting and may be removed in the future] The following sections lists all the different storage types supported. +`fs`:: + +Default file system implementation. This will pick the best implementation +depending on the operating environment: `simplefs` on Windows 32bit, `niofs` +on other 32bit systems and `mmapfs` on 64bit systems. + [[simplefs]]`simplefs`:: The Simple FS type is a straightforward implementation of file system @@ -60,13 +66,64 @@ process equal to the size of the file being mapped. Before using this class, be sure you have allowed plenty of <>. -[[default_fs]]`default_fs` deprecated[5.0.0, The `default_fs` store type is deprecated - use `mmapfs` instead]:: +[[default_fs]]`default_fs` deprecated[5.0.0, The `default_fs` store type is deprecated - use `fs` instead]:: -The `default` type is a hybrid of NIO FS and MMapFS, which chooses the best -file system for each type of file. Currently only the Lucene term dictionary, -doc values and points files are memory mapped to reduce the impact on the -operating system. All other files are opened using Lucene `NIOFSDirectory`. -Address space settings (<>) might also apply if your term -dictionary are large, if you index many fields that use points (numerics, dates -and ip addresses) or if you have many fields with doc values. +The `default` type is deprecated and is aliased to `fs` for backward +compatibility. +=== Pre-loading data into the file system cache + +experimental[This is an expert-only setting and may be removed in the future] + +By default, elasticsearch completely relies on the operating system file system +cache for caching I/O operations. It is possible to set `index.store.preload` +in order to tell the operating system to load the content of hot index +files into memory upon opening. This setting accept a comma-separated list of +files extensions: all files whose extenion is in the list will be pre-loaded +upon opening. This can be useful to improve search performance of an index, +especially when the host operating system is restarted, since this causes the +file system cache to be trashed. However note that this may slow down the +opening of indices, as they will only become available after data have been +loaded into physical memory. + +This setting is best-effort only and may not work at all depending on the store +type and host operating system. + +The `index.store.pre_load` is a static setting that can either be set in the +`config/elasticsearch.yml`: + +[source,yaml] +--------------------------------- +index.store.pre_load: ["nvd", "dvd"] +--------------------------------- + +or in the index settings at index creation time: + +[source,js] +--------------------------------- +PUT /my_index +{ + "settings": { + "index.store.pre_load": ["nvd", "dvd"] + } +} +--------------------------------- + +The default value is the empty array, which means that nothing will be loaded +into the file-system cache eagerly. For indices that are actively searched, +you might want to set it to `["nvd", "dvd"]`, which will cause norms and doc +values to be loaded eagerly into physical memory. These are the two first +extensions to look at since elasticsearch performs random access on them. + +A wildcard can be used in order to indicate that all files should be preloaded: +`index.store.pre_load: ["*"]`. Note however that it is generally not useful to +load all files into memory, in particular those for stored fields and term +vectors, so a better option might be to set it to +`["nvd", "dvd", "tim", "doc", "dim"]`, which will preload norms, doc values, +terms dictionaries, postings lists and points, which are the most important +parts of the index for search and aggregations. + +Note that this setting can be dangerous on indices that are larger than the size +of the main memory of the host, as it would cause the filesystem cache to be +trashed upon reopens after large merges, which would make indexing and searching +_slower_. From cd1a7b441cc5cef5cb3c66026a5f5ea6e74c8fa0 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 07:57:00 -0400 Subject: [PATCH 65/87] Improve error messages for lambdas when the number of arguments is wrong --- .../main/java/org/elasticsearch/painless/Def.java | 6 ++++++ .../org/elasticsearch/painless/FunctionRef.java | 7 ++++++- .../elasticsearch/painless/FunctionRefTests.java | 14 ++++++++++++++ .../org/elasticsearch/painless/LambdaTests.java | 14 ++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java index e575ed32183..8014a807b3e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java @@ -341,6 +341,12 @@ public final class Def { MethodHandle.class); handle = (MethodHandle) accessor.invokeExact(); } catch (NoSuchFieldException | IllegalAccessException e) { + // is it a synthetic method? If we generated the method ourselves, be more helpful. It can only fail + // because the arity does not match the expected interface type. + if (call.contains("$")) { + throw new IllegalArgumentException("Incorrect number of parameters for [" + interfaceMethod.name + + "] in [" + clazz.clazz + "]"); + } throw new IllegalArgumentException("Unknown call [" + call + "] with [" + arity + "] arguments."); } ref = new FunctionRef(clazz, interfaceMethod, handle, captures); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java index 6a39d99f4e3..72676f1c04c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java @@ -176,7 +176,12 @@ public class FunctionRef { * If the interface expects a primitive type to be returned, we can't return Object, * But we can set SAM to the wrapper version, and a cast will take place */ - private static MethodType adapt(MethodType expected, MethodType actual) { + private MethodType adapt(MethodType expected, MethodType actual) { + // add some checks, now that we've set everything up, to deliver exceptions as early as possible. + if (expected.parameterCount() != actual.parameterCount()) { + throw new IllegalArgumentException("Incorrect number of parameters for [" + invokedName + + "] in [" + invokedType.returnType() + "]"); + } if (expected.returnType().isPrimitive() && actual.returnType() == Object.class) { actual = actual.changeReturnType(MethodType.methodType(expected.returnType()).wrap().returnType()); } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java index 8ed2f3261cf..46d2b7c43fd 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java @@ -162,4 +162,18 @@ public class FunctionRefTests extends ScriptTestCase { exec("List l = new ArrayList(); l.add(2); l.add(1); l.sort(String::startsWith); return l.get(0);"); }); } + + public void testWrongArity() { + IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { + exec("Optional.empty().orElseGet(String::startsWith);"); + }); + assertTrue(expected.getMessage().contains("Unknown reference")); + } + + public void testWrongArityDef() { + IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { + exec("def y = Optional.empty(); return y.orElseGet(String::startsWith);"); + }); + assertTrue(expected.getMessage().contains("Unknown reference")); + } } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java index 3b008d5d6b6..01aeb440694 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java @@ -142,4 +142,18 @@ public class LambdaTests extends ScriptTestCase { assertEquals(1, exec("boolean x = false; int y = 1;" + "return Optional.empty().orElseGet(() -> x ? 5 : Optional.empty().orElseGet(() -> y));")); } + + public void testWrongArity() { + IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { + exec("Optional.empty().orElseGet(x -> x);"); + }); + assertTrue(expected.getMessage().contains("Incorrect number of parameters")); + } + + public void testWrongArityDef() { + IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { + exec("def y = Optional.empty(); return y.orElseGet(x -> x);"); + }); + assertTrue(expected.getMessage(), expected.getMessage().contains("Incorrect number of parameters")); + } } From 9111ed3e2cdfe6ac29bee1340b07400699c2db67 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 08:24:41 -0400 Subject: [PATCH 66/87] add docs --- .../elasticsearch/painless/node/ELambda.java | 23 +++++++++++++++++++ .../elasticsearch/painless/LambdaTests.java | 18 +++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java index 8adae6607a9..1d1498a51c4 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java @@ -41,6 +41,29 @@ import java.util.Set; import static org.elasticsearch.painless.WriterConstants.LAMBDA_BOOTSTRAP_HANDLE; +/** + * Lambda expression node. + *

+ * This can currently only be the direct argument of a call (method/constructor). + * When the argument is of a known type, it uses + * + * Java's lambda translation. However, if its a def call, then we don't have + * enough information, and have to defer this until link time. In that case a placeholder + * and all captures are pushed onto the stack and folded into the signature of the parent call. + *

+ * For example: + *
+ * {@code def list = new ArrayList(); int capture = 0; list.sort((x,y) -> x - y + capture)} + *
+ * is converted into a call (pseudocode) such as: + *
+ * {@code sort(list, lambda$0, capture)} + *
+ * At link time, when we know the interface type, this is decomposed with MethodHandle + * combinators back into (pseudocode): + *
+ * {@code sort(list, lambda$0(capture))} + */ public class ELambda extends AExpression implements ILambda { final String name; final FunctionReserved reserved; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java index 01aeb440694..c321b010ecf 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java @@ -85,6 +85,24 @@ public class LambdaTests extends ScriptTestCase { public void testUnneededCurlyStatements() { assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> { x + 1 })")); } + + /** interface ignores return value */ + public void testVoidReturn() { + assertEquals(2, exec("List list = new ArrayList(); " + + "list.add(2); " + + "List list2 = new ArrayList(); " + + "list.forEach(x -> list2.add(x));" + + "return list[0]")); + } + + /** interface ignores return value */ + public void testVoidReturnDef() { + assertEquals(2, exec("def list = new ArrayList(); " + + "list.add(2); " + + "List list2 = new ArrayList(); " + + "list.forEach(x -> list2.add(x));" + + "return list[0]")); + } public void testTwoLambdas() { assertEquals("testingcdefg", exec( From 28b1b149abe54909336c41b22bc7a208c54bd763 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 08:32:53 -0400 Subject: [PATCH 67/87] remove unused import --- .../src/main/java/org/elasticsearch/painless/DefMath.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java index 65a26cd3da8..f89b1429f38 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java @@ -25,7 +25,6 @@ import java.lang.invoke.MethodType; import java.lang.invoke.MethodHandles.Lookup; import java.util.Collections; import java.util.HashMap; -import java.util.IdentityHashMap; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; From 5746d96f42b82797051b59a461fe4d5b2ef8b238 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 20 Jun 2016 14:37:13 +0200 Subject: [PATCH 68/87] Catch ClosedByInterruptException when interrupting check index --- .../main/java/org/elasticsearch/index/shard/IndexShard.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 9ebbde77c6a..f20f2f5d372 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -1286,6 +1286,10 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl if (store.tryIncRef()) { try { cancellableThreads.executeIO(this::doCheckIndex); + } catch (ClosedByInterruptException ex) { + assert cancellableThreads.isCancelled(); + // that's fine we might run into this when we cancel the thread since Java NIO will close the channel on interrupt + // and on the next access we fail it. } finally { store.decRef(); } From 0660de74720b70096334b86bf237666a80a442aa Mon Sep 17 00:00:00 2001 From: Eric Sherman Date: Mon, 20 Jun 2016 08:59:57 -0500 Subject: [PATCH 69/87] Update snapshots.asciidoc (#18923) --- docs/reference/modules/snapshots.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/modules/snapshots.asciidoc b/docs/reference/modules/snapshots.asciidoc index d000805e5e9..5931dbc588f 100644 --- a/docs/reference/modules/snapshots.asciidoc +++ b/docs/reference/modules/snapshots.asciidoc @@ -8,7 +8,7 @@ backends are available via officially supported repository plugins. [float] === Repositories -Before any snapshot or restore operation can be performed a snapshot repository should be registered in +Before any snapshot or restore operation can be performed, a snapshot repository should be registered in Elasticsearch. The repository settings are repository-type specific. See below for details. [source,js] From 9510a8f39e405b98be102b81d00fe754d326ac1e Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 10:46:23 -0400 Subject: [PATCH 70/87] add a few more tests --- .../org/elasticsearch/painless/LambdaTests.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java index c321b010ecf..7b2d5e6a935 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java @@ -161,6 +161,11 @@ public class LambdaTests extends ScriptTestCase { "return Optional.empty().orElseGet(() -> x ? 5 : Optional.empty().orElseGet(() -> y));")); } + public void testNestedCaptureParams() { + assertEquals(2, exec("int foo(Function f) { return f.apply(1) }" + + "return foo(x -> foo(y -> x + 1))")); + } + public void testWrongArity() { IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("Optional.empty().orElseGet(x -> x);"); @@ -174,4 +179,12 @@ public class LambdaTests extends ScriptTestCase { }); assertTrue(expected.getMessage(), expected.getMessage().contains("Incorrect number of parameters")); } + + public void testLambdaInFunction() { + assertEquals(5, exec("def foo() { Optional.empty().orElseGet(() -> 5) } return foo();")); + } + + public void testLambdaCaptureFunctionParam() { + assertEquals(5, exec("def foo(int x) { Optional.empty().orElseGet(() -> x) } return foo(5);")); + } } From 9196ff255e3b4631ce94b143b83c2141d702166d Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 20 Jun 2016 16:46:03 +0200 Subject: [PATCH 71/87] Add extra ctor to FilterClient to support Guice proxies just don't ask it's bad but some plugins are so involved they need this. Closes #the_issue_that_never_existed --- .../java/org/elasticsearch/client/FilterClient.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/client/FilterClient.java b/core/src/main/java/org/elasticsearch/client/FilterClient.java index d2ea209a8c2..d0f52282c76 100644 --- a/core/src/main/java/org/elasticsearch/client/FilterClient.java +++ b/core/src/main/java/org/elasticsearch/client/FilterClient.java @@ -24,6 +24,8 @@ import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.support.AbstractClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.threadpool.ThreadPool; /** @@ -42,7 +44,15 @@ public abstract class FilterClient extends AbstractClient { * @see #in() */ public FilterClient(Client in) { - super(in.settings(), in.threadPool()); + this(in.settings(), in.threadPool(), in); + } + + /** + * A Constructor that allows to pass settings and threadpool separately. This is useful if the + * client is a proxy and not yet fully constructed ie. both dependencies are not available yet. + */ + protected FilterClient(Settings settings, ThreadPool threadPool, Client in) { + super(settings, threadPool); this.in = in; } From 6569d350944efbd91ec08959b23485caa2ae24b3 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 20 Jun 2016 11:49:17 -0400 Subject: [PATCH 72/87] Fail doc tests when any shard fails ES only sends a non-200 response all shards fail but we should fail the tests generated by docs if any of them fail. Depending on the outcome of #18978 this might be a temporary workaround. --- .../doc/RestTestsFromSnippetsTask.groovy | 23 +++++++++++++++---- .../modules/scripting/painless.asciidoc | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy index c9f5668a326..ba7311fee6f 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy @@ -127,7 +127,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask { current.println(setup) } - body(test) + body(test, false) } private void response(Snippet response) { @@ -136,7 +136,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask { } void emitDo(String method, String pathAndQuery, - String body, String catchPart) { + String body, String catchPart, boolean inSetup) { def (String path, String query) = pathAndQuery.tokenize('?') current.println(" - do:") if (catchPart != null) { @@ -160,6 +160,19 @@ public class RestTestsFromSnippetsTask extends SnippetsTask { current.println(" body: |") body.eachLine { current.println(" $it") } } + /* Catch any shard failures. These only cause a non-200 response if + * no shard succeeds. But we need to fail the tests on all of these + * because they mean invalid syntax or broken queries or something + * else that we don't want to teach people to do. The REST test + * framework doesn't allow us to has assertions in the setup + * section so we have to skip it there. We also have to skip _cat + * actions because they don't return json so we can't is_false + * them. That is ok because they don't have this + * partial-success-is-success thing. + */ + if (false == inSetup && false == path.startsWith('_cat')) { + current.println(" - is_false: _shards.failures") + } } private void setup(Snippet setup) { @@ -169,7 +182,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask { setupCurrent(setup) current.println('---') current.println("setup:") - body(setup) + body(setup, true) // always wait for yellow before anything is executed current.println( " - do:\n" + @@ -179,7 +192,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask { " wait_for_status: \"yellow\"") } - private void body(Snippet snippet) { + private void body(Snippet snippet, boolean inSetup) { parse("$snippet", snippet.contents, SYNTAX) { matcher, last -> if (matcher.group("comment") != null) { // Comment @@ -193,7 +206,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask { // Leading '/'s break the generated paths pathAndQuery = pathAndQuery.substring(1) } - emitDo(method, pathAndQuery, body, catchPart) + emitDo(method, pathAndQuery, body, catchPart, inSetup) } } diff --git a/docs/reference/modules/scripting/painless.asciidoc b/docs/reference/modules/scripting/painless.asciidoc index 20b301bda31..2c753e09039 100644 --- a/docs/reference/modules/scripting/painless.asciidoc +++ b/docs/reference/modules/scripting/painless.asciidoc @@ -133,7 +133,7 @@ GET hockey/_search "order": "asc", "script": { "lang": "painless", - "inline": "doc['first'].value + ' ' + doc['last'].value" + "inline": "doc['first.keyword'].value + ' ' + doc['last.keyword'].value" } } } From 26a73c39bf4ff74709b3f32bb0f96070364fe372 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 13:01:59 -0400 Subject: [PATCH 73/87] throw error if the tree is totally malformed --- .../java/org/elasticsearch/painless/node/SFunction.java | 8 ++------ .../java/org/elasticsearch/painless/node/SSource.java | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java index 629f76cdd52..d15cd07345f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SFunction.java @@ -80,12 +80,8 @@ public class SFunction extends AStatement { @Override void extractVariables(Set variables) { - for (String paramName : paramNameStrs) { - variables.add(paramName); - } - for (AStatement statement : statements) { - statement.extractVariables(variables); - } + // we should never be extracting from a function, as functions are top-level! + throw new IllegalStateException("Illegal tree structure"); } void generate() { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java index 1a47cfeba36..22ad56c1be8 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/SSource.java @@ -87,12 +87,8 @@ public final class SSource extends AStatement { @Override void extractVariables(Set variables) { - for (AStatement statement : statements) { - statement.extractVariables(variables); - } - for (SFunction function : functions) { - function.extractVariables(variables); - } + // we should never be extracting from a function, as functions are top-level! + throw new IllegalStateException("Illegal tree structure"); } public void analyze() { From 006829e89bf2bcf8e50f9e947fef7aa8626b6f01 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 13:33:51 -0400 Subject: [PATCH 74/87] add simple arguments test --- .../test/java/org/elasticsearch/painless/CastTests.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/CastTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/CastTests.java index fcee0ddeb3e..0551965f067 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/CastTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/CastTests.java @@ -162,6 +162,15 @@ public class CastTests extends ScriptTestCase { assertEquals(5, exec("def x = 5; return (int)x.longValue();")); } + /** + * Currently these do not adopt the argument value, we issue a separate cast! + */ + public void testArgumentsDef() { + assertEquals(5, exec("def x = 5L; return (+(int)x);")); + assertEquals(6, exec("def x = 5; def y = 1L; return x + (int)y")); + assertEquals('b', exec("def x = 'abcdeg'; def y = 1L; x.charAt((int)y)")); + } + /** * Unary operators adopt the return value */ From 1cc0264827e4766b01b2f781964d68819d5a93d8 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2016 14:54:45 -0400 Subject: [PATCH 75/87] Infer lambda arguments/return type --- .../org/elasticsearch/painless/Locals.java | 5 +- .../elasticsearch/painless/node/ELambda.java | 49 ++++++++++++++++--- .../painless/node/LCallInvoke.java | 15 ++++++ .../elasticsearch/painless/BasicAPITests.java | 7 ++- .../painless/DefOptimizationTests.java | 10 ++++ 5 files changed, 75 insertions(+), 11 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java index 7ffa0a169b7..ae54b6e6271 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java @@ -69,8 +69,9 @@ public final class Locals { *

* This is just like {@link #newFunctionScope}, except the captured parameters are made read-only. */ - public static Locals newLambdaScope(Locals programScope, List parameters, int captureCount, int maxLoopCounter) { - Locals locals = new Locals(programScope, Definition.DEF_TYPE); + public static Locals newLambdaScope(Locals programScope, Type returnType, List parameters, + int captureCount, int maxLoopCounter) { + Locals locals = new Locals(programScope, returnType); for (int i = 0; i < parameters.size(); i++) { Parameter parameter = parameters.get(i); boolean isCapture = i < captureCount; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java index 1d1498a51c4..e0ea5e73aeb 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java @@ -100,6 +100,44 @@ public class ELambda extends AExpression implements ILambda { @Override void analyze(Locals locals) { + final Definition.Type returnType; + final List actualParamTypeStrs; + Method interfaceMethod; + // inspect the target first, set interface method if we know it. + if (expected == null) { + interfaceMethod = null; + // we don't know anything: treat as def + returnType = Definition.DEF_TYPE; + // don't infer any types + actualParamTypeStrs = paramTypeStrs; + } else { + // we know the method statically, infer return type and any unknown/def types + interfaceMethod = expected.struct.getFunctionalMethod(); + if (interfaceMethod == null) { + throw createError(new IllegalArgumentException("Cannot pass lambda to [" + expected.name + + "], not a functional interface")); + } + // check arity before we manipulate parameters + if (interfaceMethod.arguments.size() != paramTypeStrs.size()) + throw new IllegalArgumentException("Incorrect number of parameters for [" + interfaceMethod.name + + "] in [" + expected.clazz + "]"); + // for method invocation, its allowed to ignore the return value + if (interfaceMethod.rtn == Definition.VOID_TYPE) { + returnType = Definition.DEF_TYPE; + } else { + returnType = interfaceMethod.rtn; + } + // replace any def types with the actual type (which could still be def) + actualParamTypeStrs = new ArrayList(); + for (int i = 0; i < paramTypeStrs.size(); i++) { + String paramType = paramTypeStrs.get(i); + if (paramType.equals(Definition.DEF_TYPE.name)) { + actualParamTypeStrs.add(interfaceMethod.arguments.get(i).name); + } else { + actualParamTypeStrs.add(paramType); + } + } + } // gather any variables used by the lambda body first. Set variables = new HashSet<>(); for (AStatement statement : statements) { @@ -119,14 +157,14 @@ public class ELambda extends AExpression implements ILambda { paramTypes.add(var.type.name); paramNames.add(var.name); } - paramTypes.addAll(paramTypeStrs); + paramTypes.addAll(actualParamTypeStrs); paramNames.addAll(paramNameStrs); // desugar lambda body into a synthetic method - desugared = new SFunction(reserved, location, "def", name, + desugared = new SFunction(reserved, location, returnType.name, name, paramTypes, paramNames, statements, true); desugared.generate(); - desugared.analyze(Locals.newLambdaScope(locals.getProgramScope(), desugared.parameters, + desugared.analyze(Locals.newLambdaScope(locals.getProgramScope(), returnType, desugared.parameters, captures.size(), reserved.getMaxLoopCounter())); // setup method reference to synthetic method @@ -137,11 +175,6 @@ public class ELambda extends AExpression implements ILambda { } else { defPointer = null; try { - Method interfaceMethod = expected.struct.getFunctionalMethod(); - if (interfaceMethod == null) { - throw new IllegalArgumentException("Cannot pass lambda to [" + expected.name + - "], not a functional interface"); - } Class captureClasses[] = new Class[captures.size()]; for (int i = 0; i < captures.size(); i++) { captureClasses[i] = captures.get(i).type.clazz; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java index 124755780cb..21bfff65e8d 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LCallInvoke.java @@ -21,13 +21,16 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.Definition.MethodKey; import org.elasticsearch.painless.Location; +import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Definition.Method; import org.elasticsearch.painless.Definition.Sort; import org.elasticsearch.painless.Definition.Struct; +import org.elasticsearch.painless.Definition.Type; import org.elasticsearch.painless.Globals; import org.elasticsearch.painless.Locals; import org.elasticsearch.painless.MethodWriter; +import java.lang.invoke.MethodType; import java.util.List; import java.util.Objects; import java.util.Set; @@ -41,6 +44,8 @@ public final class LCallInvoke extends ALink { final List arguments; Method method = null; + + boolean box = false; // true for primitive types public LCallInvoke(Location location, String name, List arguments) { super(location, -1); @@ -68,6 +73,12 @@ public final class LCallInvoke extends ALink { MethodKey methodKey = new MethodKey(name, arguments.size()); Struct struct = before.struct; + if (before.clazz.isPrimitive()) { + Class wrapper = MethodType.methodType(before.clazz).wrap().returnType(); + Type boxed = Definition.getType(wrapper.getSimpleName()); + struct = boxed.struct; + box = true; + } method = statik ? struct.staticMethods.get(methodKey) : struct.methods.get(methodKey); if (method != null) { @@ -103,6 +114,10 @@ public final class LCallInvoke extends ALink { @Override void load(MethodWriter writer, Globals globals) { writer.writeDebugInfo(location); + + if (box) { + writer.box(before.type); + } for (AExpression argument : arguments) { argument.write(writer, globals); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java index 885ce060aaa..ba6885eabf3 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java @@ -19,7 +19,6 @@ package org.elasticsearch.painless; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -119,4 +118,10 @@ public class BasicAPITests extends ScriptTestCase { assertEquals("{}", exec("Map map = new HashMap(); return map.toString();")); assertEquals("{}", exec("def map = new HashMap(); return map.toString();")); } + + public void testPrimitivesHaveMethods() { + assertEquals(5, exec("int x = 5; return x.intValue();")); + assertEquals("5", exec("int x = 5; return x.toString();")); + assertEquals(0, exec("int x = 5; return x.compareTo(5);")); + } } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefOptimizationTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefOptimizationTests.java index 6fb9151cb0d..da48275c829 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefOptimizationTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefOptimizationTests.java @@ -452,4 +452,14 @@ public class DefOptimizationTests extends ScriptTestCase { assertBytecodeExists("def x = 1; double y = +x; return y", "INVOKEDYNAMIC plus(Ljava/lang/Object;)D"); } + + public void testLambdaReturnType() { + assertBytecodeExists("List l = new ArrayList(); l.removeIf(x -> x < 10)", + "synthetic lambda$0(Ljava/lang/Object;)Z"); + } + + public void testLambdaArguments() { + assertBytecodeExists("List l = new ArrayList(); l.stream().mapToDouble(Double::valueOf).map(x -> x + 1)", + "synthetic lambda$0(D)D"); + } } From a3e5aeea95d39c3f7e0056481cdd4222c5f9780f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 20 Jun 2016 22:06:39 -0400 Subject: [PATCH 76/87] Add link to Discourse and IRC to --- README.textile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.textile b/README.textile index e48495a5524..7a136a91d1c 100644 --- a/README.textile +++ b/README.textile @@ -196,7 +196,14 @@ In order to play with the distributed nature of Elasticsearch, simply bring more h3. Where to go from here? -We have just covered a very small portion of what Elasticsearch is all about. For more information, please refer to the "elastic.co":http://www.elastic.co/products/elasticsearch website. +We have just covered a very small portion of what Elasticsearch is all +about. For more information, please refer to the +"elastic.co":http://www.elastic.co/products/elasticsearch +website. General questions can be asked on the "Elastic Discourse +forum":https://discuss.elastic.co or on IRC on Freenode at +"#elasticsearch":https://webchat.freenode.net/#elasticsearch. The +Elasticsearch GitHub repository is reserved for bug reports and feature +requests only. h3. Building from Source From b15bada2c8d8558b4aba73938c9d1f2f1c95009a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 20 Jun 2016 22:14:53 -0400 Subject: [PATCH 77/87] Fix newlines in README --- README.textile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.textile b/README.textile index 7a136a91d1c..d9549e5eb3c 100644 --- a/README.textile +++ b/README.textile @@ -196,14 +196,7 @@ In order to play with the distributed nature of Elasticsearch, simply bring more h3. Where to go from here? -We have just covered a very small portion of what Elasticsearch is all -about. For more information, please refer to the -"elastic.co":http://www.elastic.co/products/elasticsearch -website. General questions can be asked on the "Elastic Discourse -forum":https://discuss.elastic.co or on IRC on Freenode at -"#elasticsearch":https://webchat.freenode.net/#elasticsearch. The -Elasticsearch GitHub repository is reserved for bug reports and feature -requests only. +We have just covered a very small portion of what Elasticsearch is all about. For more information, please refer to the "elastic.co":http://www.elastic.co/products/elasticsearch website. General questions can be asked on the "Elastic Discourse forum":https://discuss.elastic.co or on IRC on Freenode at "#elasticsearch":https://webchat.freenode.net/#elasticsearch. The Elasticsearch GitHub repository is reserved for bug reports and feature requests only. h3. Building from Source From 4401517b8518459e3103ea1bbcff1d03c6f939eb Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Tue, 21 Jun 2016 08:45:46 +0200 Subject: [PATCH 78/87] Revert #18839 as it causes file leaks ``` > Throwable #1: java.lang.RuntimeException: file handle leaks: [SeekableByteChannel(/var/lib/jenkins/workspace/elastic+elasticsearch+master+g1gc/core/build/testrun/integTest/J0/temp/org.elasticsearch.search.suggest.CompletionSuggestSearch2xIT_518545A20D129C8C-001/tempDir-001/data/nodes/1/indices/4sTECv6WSJOJsw9L4CGamg/0/index/segments_1), SeekableByteChannel(/var/lib/jenkins/workspace/elastic+elasticsearch+master+g1gc/core/build/testrun/integTest/J0/temp/org.elasticsearch.search.suggest.CompletionSuggestSearch2xIT_518545A20D129C8C-001/tempDir-001/data/nodes/1/indices/4sTECv6WSJOJsw9L4CGamg/0/index/segments_1)] > at __randomizedtesting.SeedInfo.seed([518545A20D129C8C]:0) > at org.apache.lucene.mockfile.LeakFS.onClose(LeakFS.java:63) > at org.apache.lucene.mockfile.FilterFileSystem.close(FilterFileSystem.java:77) > at org.apache.lucene.mockfile.FilterFileSystem.close(FilterFileSystem.java:78) > at java.lang.Thread.run(Thread.java:745) > Caused by: java.lang.Exception > at org.apache.lucene.mockfile.LeakFS.onOpen(LeakFS.java:46) > at org.apache.lucene.mockfile.HandleTrackingFS.callOpenHook(HandleTrackingFS.java:81) > at org.apache.lucene.mockfile.HandleTrackingFS.newByteChannel(HandleTrackingFS.java:271) > at org.apache.lucene.mockfile.FilterFileSystemProvider.newByteChannel(FilterFileSystemProvider.java:212) > at org.apache.lucene.mockfile.HandleTrackingFS.newByteChannel(HandleTrackingFS.java:240) > at java.nio.file.Files.newByteChannel(Files.java:361) > at java.nio.file.Files.newByteChannel(Files.java:407) > at org.apache.lucene.store.SimpleFSDirectory.openInput(SimpleFSDirectory.java:77) > at org.apache.lucene.store.FilterDirectory.openInput(FilterDirectory.java:94) > at org.apache.lucene.util.LuceneTestCase.slowFileExists(LuceneTestCase.java:2695) > at org.apache.lucene.store.MockDirectoryWrapper.openInput(MockDirectoryWrapper.java:737) > at org.apache.lucene.store.FilterDirectory.openInput(FilterDirectory.java:94) > at org.elasticsearch.common.lucene.Lucene$1.doBody(Lucene.java:237) > at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:685) > at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:637) > at org.elasticsearch.common.lucene.Lucene.checkSegmentInfoIntegrity(Lucene.java:242) > at org.elasticsearch.index.store.Store$MetadataSnapshot.loadMetadata(Store.java:847) > at org.elasticsearch.index.store.Store$MetadataSnapshot.(Store.java:740) > at org.elasticsearch.index.store.Store.getMetadata(Store.java:260) > at org.elasticsearch.index.store.Store.getMetadata(Store.java:240) > at org.elasticsearch.index.shard.IndexShard.doCheckIndex(IndexShard.java:1310) > at org.elasticsearch.common.util.CancellableThreads.executeIO(CancellableThreads.java:102) > at org.elasticsearch.index.shard.IndexShard.checkIndex(IndexShard.java:1288) > at org.elasticsearch.index.shard.IndexShard.internalPerformTranslogRecovery(IndexShard.java:921) > at org.elasticsearch.index.shard.IndexShard.skipTranslogRecovery(IndexShard.java:964) > at org.elasticsearch.indices.recovery.RecoveryTarget.prepareForTranslogOperations(RecoveryTarget.java:297) > at ``` --- .../java/org/elasticsearch/index/shard/IndexShard.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index f20f2f5d372..959b6f8f726 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -53,7 +53,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.Callback; -import org.elasticsearch.common.util.CancellableThreads; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.SuspendableRefContainer; import org.elasticsearch.index.Index; @@ -159,7 +158,6 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl private final TranslogConfig translogConfig; private final IndexEventListener indexEventListener; private final QueryCachingPolicy cachingPolicy; - private final CancellableThreads cancellableThreads; /** @@ -267,7 +265,6 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl primaryTerm = indexSettings.getIndexMetaData().primaryTerm(shardId.id()); refreshListeners = buildRefreshListeners(); persistMetadata(shardRouting, null); - cancellableThreads = new CancellableThreads(); } public Store store() { @@ -846,7 +843,6 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl } finally { // playing safe here and close the engine even if the above succeeds - close can be called multiple times IOUtils.close(engine); } - cancellableThreads.cancel(reason); } } } @@ -1285,11 +1281,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl private void checkIndex() throws IOException { if (store.tryIncRef()) { try { - cancellableThreads.executeIO(this::doCheckIndex); - } catch (ClosedByInterruptException ex) { - assert cancellableThreads.isCancelled(); - // that's fine we might run into this when we cancel the thread since Java NIO will close the channel on interrupt - // and on the next access we fail it. + doCheckIndex(); } finally { store.decRef(); } From 82f7bfad98253e94305136df481cd1c7dc4e8ca8 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 13 Jun 2016 12:21:20 +0200 Subject: [PATCH 79/87] ingest: merged o.e.ingest.core with o.e.ingest and in ingest-common module added o.e.ingest.common package and moved all code to that package. --- .../resources/checkstyle_suppressions.xml | 13 ------ .../admin/cluster/node/info/NodeInfo.java | 2 +- .../ingest/PutPipelineTransportAction.java | 2 +- .../ingest/SimulateDocumentBaseResult.java | 2 +- .../ingest/SimulateExecutionService.java | 6 +-- .../ingest/SimulatePipelineRequest.java | 8 ++-- .../ingest/SimulateProcessorResult.java | 4 +- .../ingest/TrackingResultProcessor.java | 6 +-- .../ingest/WriteableIngestDocument.java | 2 +- .../ingest/{core => }/AbstractProcessor.java | 3 +- .../{core => }/AbstractProcessorFactory.java | 3 +- .../ingest/{core => }/CompoundProcessor.java | 5 ++- .../ingest/{core => }/ConfigurationUtils.java | 3 +- .../ingest/{core => }/IngestDocument.java | 44 ++++++++++++------- .../ingest/{core => }/IngestInfo.java | 2 +- .../elasticsearch/ingest/IngestService.java | 3 -- .../ingest/InternalTemplateService.java | 1 - .../ingest/{core => }/Pipeline.java | 13 +++--- .../ingest/PipelineExecutionService.java | 7 +-- .../elasticsearch/ingest/PipelineStore.java | 16 +++---- .../ingest/{core => }/Processor.java | 2 +- .../ingest/{core => }/ProcessorInfo.java | 2 +- .../ingest/ProcessorsRegistry.java | 2 - .../ingest/{core => }/TemplateService.java | 2 +- .../ingest/{core => }/ValueSource.java | 2 +- .../org/elasticsearch/node/NodeModule.java | 3 +- .../ingest/IngestActionFilterTests.java | 7 ++- .../SimulateDocumentSimpleResultTests.java | 4 +- .../ingest/SimulateExecutionServiceTests.java | 8 ++-- .../SimulatePipelineRequestParsingTests.java | 14 +++--- .../ingest/SimulatePipelineResponseTests.java | 4 +- .../ingest/SimulateProcessorResultTests.java | 4 +- .../ingest/TrackingResultProcessorTests.java | 12 +++-- .../ingest/WriteableIngestDocumentTests.java | 4 +- .../{core => }/CompoundProcessorTests.java | 3 +- .../{core => }/ConfigurationUtilsTests.java | 4 +- .../elasticsearch/ingest/IngestClientIT.java | 1 - .../elasticsearch/ingest/IngestCloseIT.java | 2 - .../{core => }/IngestDocumentTests.java | 4 +- ...gestProcessorNotInstalledOnAllNodesIT.java | 1 - .../ingest/PipelineExecutionServiceTests.java | 4 -- .../{core => }/PipelineFactoryTests.java | 7 +-- .../ingest/PipelineStoreTests.java | 5 --- .../ingest/{core => }/ValueSourceTests.java | 4 +- .../nodesinfo/NodeInfoStreamingTests.java | 2 +- modules/ingest-common/build.gradle | 2 +- .../{ => common}/AbstractStringProcessor.java | 10 ++--- .../ingest/{ => common}/AppendProcessor.java | 14 +++--- .../ingest/{ => common}/ConvertProcessor.java | 12 ++--- .../ingest/{ => common}/DateFormat.java | 2 +- .../{ => common}/DateIndexNameProcessor.java | 10 ++--- .../ingest/{ => common}/DateProcessor.java | 10 ++--- .../ingest/{ => common}/FailProcessor.java | 12 ++--- .../{ => common}/FailProcessorException.java | 9 ++-- .../ingest/{ => common}/ForEachProcessor.java | 17 +++---- .../ingest/{ => common}/Grok.java | 2 +- .../ingest/{ => common}/GrokMatchGroup.java | 2 +- .../ingest/{ => common}/GrokProcessor.java | 12 ++--- .../ingest/{ => common}/GsubProcessor.java | 12 ++--- .../{ => common}/IngestCommonPlugin.java | 2 +- .../ingest/{ => common}/JoinProcessor.java | 10 ++--- .../{ => common}/LowercaseProcessor.java | 2 +- .../ingest/{ => common}/RemoveProcessor.java | 12 ++--- .../ingest/{ => common}/RenameProcessor.java | 10 ++--- .../ingest/{ => common}/ScriptProcessor.java | 14 +++--- .../ingest/{ => common}/SetProcessor.java | 14 +++--- .../ingest/{ => common}/SortProcessor.java | 10 ++--- .../ingest/{ => common}/SplitProcessor.java | 10 ++--- .../ingest/{ => common}/TrimProcessor.java | 2 +- .../{ => common}/UppercaseProcessor.java | 2 +- .../AbstractStringProcessorTestCase.java | 7 +-- .../AppendProcessorFactoryTests.java | 5 ++- .../{ => common}/AppendProcessorTests.java | 12 ++--- .../ConvertProcessorFactoryTests.java | 4 +- .../{ => common}/ConvertProcessorTests.java | 9 ++-- .../ingest/{ => common}/DateFormatTests.java | 2 +- .../DateIndexNameFactoryTests.java | 2 +- .../DateIndexNameProcessorTests.java | 4 +- .../DateProcessorFactoryTests.java | 4 +- .../{ => common}/DateProcessorTests.java | 5 ++- .../FailProcessorFactoryTests.java | 5 ++- .../{ => common}/FailProcessorTests.java | 8 ++-- .../ForEachProcessorFactoryTests.java | 6 ++- .../{ => common}/ForEachProcessorTests.java | 14 +++--- .../GrokProcessorFactoryTests.java | 4 +- .../{ => common}/GrokProcessorTests.java | 5 +-- .../ingest/{ => common}/GrokTests.java | 2 +- .../GsubProcessorFactoryTests.java | 4 +- .../{ => common}/GsubProcessorTests.java | 7 +-- .../{ => common}/IngestCommonRestIT.java | 2 +- .../JoinProcessorFactoryTests.java | 4 +- .../{ => common}/JoinProcessorTests.java | 7 +-- .../LowercaseProcessorFactoryTests.java | 4 +- .../{ => common}/LowercaseProcessorTests.java | 2 +- .../RemoveProcessorFactoryTests.java | 5 ++- .../{ => common}/RemoveProcessorTests.java | 8 ++-- .../RenameProcessorFactoryTests.java | 4 +- .../{ => common}/RenameProcessorTests.java | 7 +-- .../ScriptProcessorFactoryTests.java | 2 +- .../{ => common}/ScriptProcessorTests.java | 5 ++- .../SetProcessorFactoryTests.java | 5 ++- .../{ => common}/SetProcessorTests.java | 12 ++--- .../{ => common}/SortProcessorTests.java | 9 ++-- .../SplitProcessorFactoryTests.java | 4 +- .../{ => common}/SplitProcessorTests.java | 7 +-- .../TrimProcessorFactoryTests.java | 4 +- .../{ => common}/TrimProcessorTests.java | 2 +- .../UppercaseProcessorFactoryTests.java | 4 +- .../{ => common}/UppercaseProcessorTests.java | 2 +- .../attachment/AttachmentProcessor.java | 14 +++--- .../AttachmentProcessorFactoryTests.java | 2 +- .../attachment/AttachmentProcessorTests.java | 2 +- .../ingest/geoip/GeoIpProcessor.java | 21 +++++---- .../geoip/GeoIpProcessorFactoryTests.java | 14 +++--- .../ingest/geoip/GeoIpProcessorTests.java | 14 +++--- .../ingest/AbstractScriptTestCase.java | 1 - .../ingest/IngestDocumentMustacheIT.java | 3 -- .../ingest/TemplateServiceIT.java | 2 - .../ingest/ValueSourceMustacheIT.java | 3 -- .../ingest/RandomDocumentPicks.java | 1 - .../elasticsearch/ingest/TestProcessor.java | 4 -- .../ingest/TestTemplateService.java | 2 - 122 files changed, 372 insertions(+), 385 deletions(-) rename core/src/main/java/org/elasticsearch/ingest/{core => }/AbstractProcessor.java (96%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/AbstractProcessorFactory.java (97%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/CompoundProcessor.java (97%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/ConfigurationUtils.java (99%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/IngestDocument.java (95%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/IngestInfo.java (98%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/Pipeline.java (90%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/Processor.java (97%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/ProcessorInfo.java (98%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/TemplateService.java (97%) rename core/src/main/java/org/elasticsearch/ingest/{core => }/ValueSource.java (99%) rename core/src/test/java/org/elasticsearch/ingest/{core => }/CompoundProcessorTests.java (99%) rename core/src/test/java/org/elasticsearch/ingest/{core => }/ConfigurationUtilsTests.java (97%) rename core/src/test/java/org/elasticsearch/ingest/{core => }/IngestDocumentTests.java (99%) rename core/src/test/java/org/elasticsearch/ingest/{core => }/PipelineFactoryTests.java (96%) rename core/src/test/java/org/elasticsearch/ingest/{core => }/ValueSourceTests.java (95%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/AbstractStringProcessor.java (89%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/AppendProcessor.java (87%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/ConvertProcessor.java (94%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/DateFormat.java (98%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/DateIndexNameProcessor.java (95%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/DateProcessor.java (94%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/FailProcessor.java (86%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/FailProcessorException.java (79%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/ForEachProcessor.java (87%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/Grok.java (99%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/GrokMatchGroup.java (97%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/GrokProcessor.java (94%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/GsubProcessor.java (89%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/IngestCommonPlugin.java (99%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/JoinProcessor.java (90%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/LowercaseProcessor.java (97%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/RemoveProcessor.java (86%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/RenameProcessor.java (91%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/ScriptProcessor.java (91%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/SetProcessor.java (89%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/SortProcessor.java (93%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/SplitProcessor.java (90%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/TrimProcessor.java (97%) rename modules/ingest-common/src/main/java/org/elasticsearch/ingest/{ => common}/UppercaseProcessor.java (97%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/AbstractStringProcessorTestCase.java (95%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/AppendProcessorFactoryTests.java (95%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/AppendProcessorTests.java (96%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/ConvertProcessorFactoryTests.java (97%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/ConvertProcessorTests.java (98%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/DateFormatTests.java (98%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/DateIndexNameFactoryTests.java (99%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/DateIndexNameProcessorTests.java (97%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/DateProcessorFactoryTests.java (98%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/DateProcessorTests.java (98%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/FailProcessorFactoryTests.java (93%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/FailProcessorTests.java (86%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/ForEachProcessorFactoryTests.java (94%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/ForEachProcessorTests.java (95%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/GrokProcessorFactoryTests.java (98%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/GrokProcessorTests.java (98%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/GrokTests.java (99%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/GsubProcessorFactoryTests.java (97%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/GsubProcessorTests.java (95%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/IngestCommonRestIT.java (97%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/JoinProcessorFactoryTests.java (96%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/JoinProcessorTests.java (96%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/LowercaseProcessorFactoryTests.java (95%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/LowercaseProcessorTests.java (96%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/RemoveProcessorFactoryTests.java (93%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/RemoveProcessorTests.java (90%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/RenameProcessorFactoryTests.java (96%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/RenameProcessorTests.java (97%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/ScriptProcessorFactoryTests.java (98%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/ScriptProcessorTests.java (95%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/SetProcessorFactoryTests.java (96%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/SetProcessorTests.java (94%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/SortProcessorTests.java (98%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/SplitProcessorFactoryTests.java (96%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/SplitProcessorTests.java (96%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/TrimProcessorFactoryTests.java (95%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/TrimProcessorTests.java (97%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/UppercaseProcessorFactoryTests.java (95%) rename modules/ingest-common/src/test/java/org/elasticsearch/ingest/{ => common}/UppercaseProcessorTests.java (96%) diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index 27b9efbf0a4..fbc5d149d99 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -495,11 +495,6 @@ - - - - - @@ -1025,11 +1020,6 @@ - - - - - @@ -1206,9 +1196,6 @@ - - - diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java index 87ec2d052ab..068f974d893 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.http.HttpInfo; -import org.elasticsearch.ingest.core.IngestInfo; +import org.elasticsearch.ingest.IngestInfo; import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.monitor.os.OsInfo; import org.elasticsearch.monitor.process.ProcessInfo; diff --git a/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineTransportAction.java b/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineTransportAction.java index bea5a2c8bc3..df92567b98d 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineTransportAction.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/PutPipelineTransportAction.java @@ -35,7 +35,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.ingest.PipelineStore; -import org.elasticsearch.ingest.core.IngestInfo; +import org.elasticsearch.ingest.IngestInfo; import org.elasticsearch.node.service.NodeService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; diff --git a/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java b/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java index d444922cfc3..8521484370c 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java @@ -22,7 +22,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import java.io.IOException; diff --git a/core/src/main/java/org/elasticsearch/action/ingest/SimulateExecutionService.java b/core/src/main/java/org/elasticsearch/action/ingest/SimulateExecutionService.java index 2636dcb3ba8..db7397ba1f8 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/SimulateExecutionService.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/SimulateExecutionService.java @@ -21,9 +21,9 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRunnable; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Pipeline; -import org.elasticsearch.ingest.core.CompoundProcessor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Pipeline; +import org.elasticsearch.ingest.CompoundProcessor; import org.elasticsearch.threadpool.ThreadPool; import java.util.ArrayList; diff --git a/core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java b/core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java index 14092ad62cb..ce24969e8f2 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java @@ -24,9 +24,9 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.ingest.core.ConfigurationUtils; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Pipeline; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Pipeline; import org.elasticsearch.ingest.PipelineStore; import java.io.IOException; @@ -35,7 +35,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import static org.elasticsearch.ingest.core.IngestDocument.MetaData; +import static org.elasticsearch.ingest.IngestDocument.MetaData; public class SimulatePipelineRequest extends ActionRequest { diff --git a/core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java b/core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java index ba7ef195aad..6924550d79b 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java @@ -24,8 +24,8 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.IngestDocument; import java.io.IOException; diff --git a/core/src/main/java/org/elasticsearch/action/ingest/TrackingResultProcessor.java b/core/src/main/java/org/elasticsearch/action/ingest/TrackingResultProcessor.java index 3693b5dcac7..b91c7b14fee 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/TrackingResultProcessor.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/TrackingResultProcessor.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.ingest; -import org.elasticsearch.ingest.core.CompoundProcessor; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.CompoundProcessor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; import java.util.ArrayList; import java.util.List; diff --git a/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java b/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java index a0416fe8338..137914701db 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import java.io.IOException; import java.util.Map; diff --git a/core/src/main/java/org/elasticsearch/ingest/core/AbstractProcessor.java b/core/src/main/java/org/elasticsearch/ingest/AbstractProcessor.java similarity index 96% rename from core/src/main/java/org/elasticsearch/ingest/core/AbstractProcessor.java rename to core/src/main/java/org/elasticsearch/ingest/AbstractProcessor.java index e709ae395cb..c7204ee3e69 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/AbstractProcessor.java +++ b/core/src/main/java/org/elasticsearch/ingest/AbstractProcessor.java @@ -17,8 +17,7 @@ * under the License. */ - -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; /** * An Abstract Processor that holds a processorTag field to be used diff --git a/core/src/main/java/org/elasticsearch/ingest/core/AbstractProcessorFactory.java b/core/src/main/java/org/elasticsearch/ingest/AbstractProcessorFactory.java similarity index 97% rename from core/src/main/java/org/elasticsearch/ingest/core/AbstractProcessorFactory.java rename to core/src/main/java/org/elasticsearch/ingest/AbstractProcessorFactory.java index 323344f8f41..0fb50228793 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/AbstractProcessorFactory.java +++ b/core/src/main/java/org/elasticsearch/ingest/AbstractProcessorFactory.java @@ -17,8 +17,7 @@ * under the License. */ - -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import java.util.Map; diff --git a/core/src/main/java/org/elasticsearch/ingest/core/CompoundProcessor.java b/core/src/main/java/org/elasticsearch/ingest/CompoundProcessor.java similarity index 97% rename from core/src/main/java/org/elasticsearch/ingest/core/CompoundProcessor.java rename to core/src/main/java/org/elasticsearch/ingest/CompoundProcessor.java index 652a2c184a2..4af2e8a811a 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/CompoundProcessor.java +++ b/core/src/main/java/org/elasticsearch/ingest/CompoundProcessor.java @@ -18,7 +18,7 @@ */ //TODO(simonw): can all these classes go into org.elasticsearch.ingest? -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.ElasticsearchException; @@ -103,7 +103,8 @@ public class CompoundProcessor implements Processor { continue; } - ElasticsearchException compoundProcessorException = newCompoundProcessorException(e, processor.getType(), processor.getTag()); + ElasticsearchException compoundProcessorException = + newCompoundProcessorException(e, processor.getType(), processor.getTag()); if (onFailureProcessors.isEmpty()) { throw compoundProcessorException; } else { diff --git a/core/src/main/java/org/elasticsearch/ingest/core/ConfigurationUtils.java b/core/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java similarity index 99% rename from core/src/main/java/org/elasticsearch/ingest/core/ConfigurationUtils.java rename to core/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java index 20370430bdc..d87a59fd625 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/ConfigurationUtils.java +++ b/core/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java @@ -17,10 +17,9 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.ProcessorsRegistry; import java.util.ArrayList; import java.util.Arrays; diff --git a/core/src/main/java/org/elasticsearch/ingest/core/IngestDocument.java b/core/src/main/java/org/elasticsearch/ingest/IngestDocument.java similarity index 95% rename from core/src/main/java/org/elasticsearch/ingest/core/IngestDocument.java rename to core/src/main/java/org/elasticsearch/ingest/IngestDocument.java index 8b1f02607d8..80bbd52bcf6 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/IngestDocument.java +++ b/core/src/main/java/org/elasticsearch/ingest/IngestDocument.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.common.Strings; import org.elasticsearch.index.mapper.internal.IdFieldMapper; @@ -56,7 +56,8 @@ public final class IngestDocument { private final Map sourceAndMetadata; private final Map ingestMetadata; - public IngestDocument(String index, String type, String id, String routing, String parent, String timestamp, String ttl, Map source) { + public IngestDocument(String index, String type, String id, String routing, String parent, String timestamp, + String ttl, Map source) { this.sourceAndMetadata = new HashMap<>(); this.sourceAndMetadata.putAll(source); this.sourceAndMetadata.put(MetaData.INDEX.getFieldName(), index); @@ -251,10 +252,12 @@ public final class IngestDocument { try { index = Integer.parseInt(leafKey); } catch (NumberFormatException e) { - throw new IllegalArgumentException("[" + leafKey + "] is not an integer, cannot be used as an index as part of path [" + path + "]", e); + throw new IllegalArgumentException("[" + leafKey + "] is not an integer, cannot be used as an index as part of path [" + + path + "]", e); } if (index < 0 || index >= list.size()) { - throw new IllegalArgumentException("[" + index + "] is out of bounds for array with length [" + list.size() + "] as part of path [" + path + "]"); + throw new IllegalArgumentException("[" + index + "] is out of bounds for array with length [" + list.size() + + "] as part of path [" + path + "]"); } list.remove(index); return; @@ -263,7 +266,8 @@ public final class IngestDocument { if (context == null) { throw new IllegalArgumentException("cannot remove [" + leafKey + "] from null as part of path [" + path + "]"); } - throw new IllegalArgumentException("cannot remove [" + leafKey + "] from object of type [" + context.getClass().getName() + "] as part of path [" + path + "]"); + throw new IllegalArgumentException("cannot remove [" + leafKey + "] from object of type [" + context.getClass().getName() + + "] as part of path [" + path + "]"); } private static Object resolve(String pathElement, String fullPath, Object context) { @@ -285,14 +289,17 @@ public final class IngestDocument { try { index = Integer.parseInt(pathElement); } catch (NumberFormatException e) { - throw new IllegalArgumentException("[" + pathElement + "] is not an integer, cannot be used as an index as part of path [" + fullPath + "]", e); + throw new IllegalArgumentException("[" + pathElement + "] is not an integer, cannot be used as an index as part of path [" + + fullPath + "]", e); } if (index < 0 || index >= list.size()) { - throw new IllegalArgumentException("[" + index + "] is out of bounds for array with length [" + list.size() + "] as part of path [" + fullPath + "]"); + throw new IllegalArgumentException("[" + index + "] is out of bounds for array with length [" + list.size() + + "] as part of path [" + fullPath + "]"); } return list.get(index); } - throw new IllegalArgumentException("cannot resolve [" + pathElement + "] from object of type [" + context.getClass().getName() + "] as part of path [" + fullPath + "]"); + throw new IllegalArgumentException("cannot resolve [" + pathElement + "] from object of type [" + context.getClass().getName() + + "] as part of path [" + fullPath + "]"); } /** @@ -381,14 +388,17 @@ public final class IngestDocument { try { index = Integer.parseInt(pathElement); } catch (NumberFormatException e) { - throw new IllegalArgumentException("[" + pathElement + "] is not an integer, cannot be used as an index as part of path [" + path + "]", e); + throw new IllegalArgumentException("[" + pathElement + + "] is not an integer, cannot be used as an index as part of path [" + path + "]", e); } if (index < 0 || index >= list.size()) { - throw new IllegalArgumentException("[" + index + "] is out of bounds for array with length [" + list.size() + "] as part of path [" + path + "]"); + throw new IllegalArgumentException("[" + index + "] is out of bounds for array with length [" + + list.size() + "] as part of path [" + path + "]"); } context = list.get(index); } else { - throw new IllegalArgumentException("cannot resolve [" + pathElement + "] from object of type [" + context.getClass().getName() + "] as part of path [" + path + "]"); + throw new IllegalArgumentException("cannot resolve [" + pathElement + "] from object of type [" + + context.getClass().getName() + "] as part of path [" + path + "]"); } } @@ -421,10 +431,12 @@ public final class IngestDocument { try { index = Integer.parseInt(leafKey); } catch (NumberFormatException e) { - throw new IllegalArgumentException("[" + leafKey + "] is not an integer, cannot be used as an index as part of path [" + path + "]", e); + throw new IllegalArgumentException("[" + leafKey + "] is not an integer, cannot be used as an index as part of path [" + + path + "]", e); } if (index < 0 || index >= list.size()) { - throw new IllegalArgumentException("[" + index + "] is out of bounds for array with length [" + list.size() + "] as part of path [" + path + "]"); + throw new IllegalArgumentException("[" + index + "] is out of bounds for array with length [" + list.size() + + "] as part of path [" + path + "]"); } if (append) { Object object = list.get(index); @@ -436,7 +448,8 @@ public final class IngestDocument { } list.set(index, value); } else { - throw new IllegalArgumentException("cannot set [" + leafKey + "] with parent object of type [" + context.getClass().getName() + "] as part of path [" + path + "]"); + throw new IllegalArgumentException("cannot set [" + leafKey + "] with parent object of type [" + + context.getClass().getName() + "] as part of path [" + path + "]"); } } @@ -471,7 +484,8 @@ public final class IngestDocument { if (clazz.isInstance(object)) { return clazz.cast(object); } - throw new IllegalArgumentException("field [" + path + "] of type [" + object.getClass().getName() + "] cannot be cast to [" + clazz.getName() + "]"); + throw new IllegalArgumentException("field [" + path + "] of type [" + object.getClass().getName() + "] cannot be cast to [" + + clazz.getName() + "]"); } public String renderTemplate(TemplateService.Template template) { diff --git a/core/src/main/java/org/elasticsearch/ingest/core/IngestInfo.java b/core/src/main/java/org/elasticsearch/ingest/IngestInfo.java similarity index 98% rename from core/src/main/java/org/elasticsearch/ingest/core/IngestInfo.java rename to core/src/main/java/org/elasticsearch/ingest/IngestInfo.java index 1d72c6f86a1..7dbce888bba 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/IngestInfo.java +++ b/core/src/main/java/org/elasticsearch/ingest/IngestInfo.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; diff --git a/core/src/main/java/org/elasticsearch/ingest/IngestService.java b/core/src/main/java/org/elasticsearch/ingest/IngestService.java index 60fb3c26eea..228de5b37bc 100644 --- a/core/src/main/java/org/elasticsearch/ingest/IngestService.java +++ b/core/src/main/java/org/elasticsearch/ingest/IngestService.java @@ -21,9 +21,6 @@ package org.elasticsearch.ingest; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.ingest.core.IngestInfo; -import org.elasticsearch.ingest.core.Processor; -import org.elasticsearch.ingest.core.ProcessorInfo; import org.elasticsearch.script.ScriptService; import org.elasticsearch.threadpool.ThreadPool; diff --git a/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java b/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java index 3a3fae9e997..2e1f1415b42 100644 --- a/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java +++ b/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java @@ -20,7 +20,6 @@ package org.elasticsearch.ingest; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.ingest.core.TemplateService; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; diff --git a/core/src/main/java/org/elasticsearch/ingest/core/Pipeline.java b/core/src/main/java/org/elasticsearch/ingest/Pipeline.java similarity index 90% rename from core/src/main/java/org/elasticsearch/ingest/core/Pipeline.java rename to core/src/main/java/org/elasticsearch/ingest/Pipeline.java index d0b1ca7f6cf..bea02f49358 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/Pipeline.java +++ b/core/src/main/java/org/elasticsearch/ingest/Pipeline.java @@ -17,17 +17,15 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.ProcessorsRegistry; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; - /** * A pipeline is a list of {@link Processor} instances grouped under a unique id. */ @@ -104,12 +102,15 @@ public final class Pipeline { String description = ConfigurationUtils.readOptionalStringProperty(null, null, config, DESCRIPTION_KEY); List>> processorConfigs = ConfigurationUtils.readList(null, null, config, PROCESSORS_KEY); List processors = ConfigurationUtils.readProcessorConfigs(processorConfigs, processorRegistry); - List>> onFailureProcessorConfigs = ConfigurationUtils.readOptionalList(null, null, config, ON_FAILURE_KEY); + List>> onFailureProcessorConfigs = + ConfigurationUtils.readOptionalList(null, null, config, ON_FAILURE_KEY); List onFailureProcessors = ConfigurationUtils.readProcessorConfigs(onFailureProcessorConfigs, processorRegistry); if (config.isEmpty() == false) { - throw new ElasticsearchParseException("pipeline [" + id + "] doesn't support one or more provided configuration parameters " + Arrays.toString(config.keySet().toArray())); + throw new ElasticsearchParseException("pipeline [" + id + + "] doesn't support one or more provided configuration parameters " + Arrays.toString(config.keySet().toArray())); } - CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.unmodifiableList(processors), Collections.unmodifiableList(onFailureProcessors)); + CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.unmodifiableList(processors), + Collections.unmodifiableList(onFailureProcessors)); return new Pipeline(id, description, compoundProcessor); } diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineExecutionService.java b/core/src/main/java/org/elasticsearch/ingest/PipelineExecutionService.java index 8674e805974..ef726e44843 100644 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineExecutionService.java +++ b/core/src/main/java/org/elasticsearch/ingest/PipelineExecutionService.java @@ -19,18 +19,14 @@ package org.elasticsearch.ingest; -import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.cluster.ClusterChangedEvent; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.common.Strings; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.metrics.MeanMetric; import org.elasticsearch.common.util.concurrent.AbstractRunnable; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Pipeline; import org.elasticsearch.threadpool.ThreadPool; import java.util.Collections; @@ -90,7 +86,8 @@ public class PipelineExecutionService implements ClusterStateListener { if (Strings.hasText(indexRequest.getPipeline())) { try { innerExecute(indexRequest, getPipeline(indexRequest.getPipeline())); - //this shouldn't be needed here but we do it for consistency with index api which requires it to prevent double execution + //this shouldn't be needed here but we do it for consistency with index api + // which requires it to prevent double execution indexRequest.setPipeline(null); } catch (Throwable e) { itemFailureHandler.accept(indexRequest, e); diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java b/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java index 54cd716f0e8..f96a7179656 100644 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java +++ b/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java @@ -37,10 +37,6 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.ingest.core.IngestInfo; -import org.elasticsearch.ingest.core.Pipeline; -import org.elasticsearch.ingest.core.Processor; -import org.elasticsearch.ingest.core.TemplateService; import org.elasticsearch.script.ScriptService; import java.io.Closeable; @@ -66,7 +62,8 @@ public class PipelineStore extends AbstractComponent implements Closeable, Clust super(settings); } - public void buildProcessorFactoryRegistry(ProcessorsRegistry.Builder processorsRegistryBuilder, ScriptService scriptService, ClusterService clusterService) { + public void buildProcessorFactoryRegistry(ProcessorsRegistry.Builder processorsRegistryBuilder, ScriptService scriptService, + ClusterService clusterService) { this.processorRegistry = processorsRegistryBuilder.build(scriptService, clusterService); } @@ -105,7 +102,8 @@ public class PipelineStore extends AbstractComponent implements Closeable, Clust * Deletes the pipeline specified by id in the request. */ public void delete(ClusterService clusterService, DeletePipelineRequest request, ActionListener listener) { - clusterService.submitStateUpdateTask("delete-pipeline-" + request.getId(), new AckedClusterStateUpdateTask(request, listener) { + clusterService.submitStateUpdateTask("delete-pipeline-" + request.getId(), + new AckedClusterStateUpdateTask(request, listener) { @Override protected WritePipelineResponse newResponse(boolean acknowledged) { @@ -141,10 +139,12 @@ public class PipelineStore extends AbstractComponent implements Closeable, Clust /** * Stores the specified pipeline definition in the request. */ - public void put(ClusterService clusterService, Map ingestInfos, PutPipelineRequest request, ActionListener listener) throws Exception { + public void put(ClusterService clusterService, Map ingestInfos, PutPipelineRequest request, + ActionListener listener) throws Exception { // validates the pipeline and processor configuration before submitting a cluster update task: validatePipeline(ingestInfos, request); - clusterService.submitStateUpdateTask("put-pipeline-" + request.getId(), new AckedClusterStateUpdateTask(request, listener) { + clusterService.submitStateUpdateTask("put-pipeline-" + request.getId(), + new AckedClusterStateUpdateTask(request, listener) { @Override protected WritePipelineResponse newResponse(boolean acknowledged) { diff --git a/core/src/main/java/org/elasticsearch/ingest/core/Processor.java b/core/src/main/java/org/elasticsearch/ingest/Processor.java similarity index 97% rename from core/src/main/java/org/elasticsearch/ingest/core/Processor.java rename to core/src/main/java/org/elasticsearch/ingest/Processor.java index 8cdff8714c4..92c18464e94 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/Processor.java +++ b/core/src/main/java/org/elasticsearch/ingest/Processor.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import java.util.Map; diff --git a/core/src/main/java/org/elasticsearch/ingest/core/ProcessorInfo.java b/core/src/main/java/org/elasticsearch/ingest/ProcessorInfo.java similarity index 98% rename from core/src/main/java/org/elasticsearch/ingest/core/ProcessorInfo.java rename to core/src/main/java/org/elasticsearch/ingest/ProcessorInfo.java index a98b446fce0..a7a2d122ed8 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/ProcessorInfo.java +++ b/core/src/main/java/org/elasticsearch/ingest/ProcessorInfo.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; diff --git a/core/src/main/java/org/elasticsearch/ingest/ProcessorsRegistry.java b/core/src/main/java/org/elasticsearch/ingest/ProcessorsRegistry.java index 88a021d2059..28abfc45313 100644 --- a/core/src/main/java/org/elasticsearch/ingest/ProcessorsRegistry.java +++ b/core/src/main/java/org/elasticsearch/ingest/ProcessorsRegistry.java @@ -21,8 +21,6 @@ package org.elasticsearch.ingest; import org.apache.lucene.util.IOUtils; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.ingest.core.Processor; -import org.elasticsearch.ingest.core.TemplateService; import org.elasticsearch.script.ScriptService; import java.io.Closeable; diff --git a/core/src/main/java/org/elasticsearch/ingest/core/TemplateService.java b/core/src/main/java/org/elasticsearch/ingest/TemplateService.java similarity index 97% rename from core/src/main/java/org/elasticsearch/ingest/core/TemplateService.java rename to core/src/main/java/org/elasticsearch/ingest/TemplateService.java index 8988c924c35..2ece5a94304 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/TemplateService.java +++ b/core/src/main/java/org/elasticsearch/ingest/TemplateService.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import java.util.Map; diff --git a/core/src/main/java/org/elasticsearch/ingest/core/ValueSource.java b/core/src/main/java/org/elasticsearch/ingest/ValueSource.java similarity index 99% rename from core/src/main/java/org/elasticsearch/ingest/core/ValueSource.java rename to core/src/main/java/org/elasticsearch/ingest/ValueSource.java index 1a38b967e62..fa483a5fbee 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/ValueSource.java +++ b/core/src/main/java/org/elasticsearch/ingest/ValueSource.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import java.util.ArrayList; import java.util.Arrays; diff --git a/core/src/main/java/org/elasticsearch/node/NodeModule.java b/core/src/main/java/org/elasticsearch/node/NodeModule.java index 85cfe5bd6b2..6d8be732dd2 100644 --- a/core/src/main/java/org/elasticsearch/node/NodeModule.java +++ b/core/src/main/java/org/elasticsearch/node/NodeModule.java @@ -22,7 +22,8 @@ package org.elasticsearch.node; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.ingest.ProcessorsRegistry; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.TemplateService; import org.elasticsearch.monitor.MonitorService; import org.elasticsearch.node.service.NodeService; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/IngestActionFilterTests.java b/core/src/test/java/org/elasticsearch/action/ingest/IngestActionFilterTests.java index d4bccafecbf..b04533fafc4 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/IngestActionFilterTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/IngestActionFilterTests.java @@ -33,10 +33,9 @@ import org.elasticsearch.ingest.IngestService; import org.elasticsearch.ingest.PipelineExecutionService; import org.elasticsearch.ingest.PipelineStore; import org.elasticsearch.ingest.TestProcessor; -import org.elasticsearch.ingest.core.CompoundProcessor; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Pipeline; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.CompoundProcessor; +import org.elasticsearch.ingest.Pipeline; +import org.elasticsearch.ingest.Processor; import org.elasticsearch.node.service.NodeService; import org.elasticsearch.tasks.Task; import org.elasticsearch.test.ESTestCase; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java index 52c13b92701..323a8c0aaa6 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateDocumentSimpleResultTests.java @@ -22,12 +22,12 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.ingest.RandomDocumentPicks; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.test.ESTestCase; import java.io.IOException; -import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; +import static org.elasticsearch.ingest.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java index f7f2f0212dd..a7bc76341b8 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java @@ -23,9 +23,9 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.ingest.TestProcessor; -import org.elasticsearch.ingest.core.CompoundProcessor; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Pipeline; +import org.elasticsearch.ingest.CompoundProcessor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Pipeline; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.junit.After; @@ -34,7 +34,7 @@ import org.junit.Before; import java.util.Collections; import java.util.Map; -import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; +import static org.elasticsearch.ingest.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.not; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java index 4b50f69e4c8..fa4bdc6525d 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineRequestParsingTests.java @@ -24,10 +24,10 @@ import org.elasticsearch.ingest.PipelineStore; import org.elasticsearch.ingest.ProcessorsRegistry; import org.elasticsearch.ingest.TestProcessor; import org.elasticsearch.ingest.TestTemplateService; -import org.elasticsearch.ingest.core.CompoundProcessor; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Pipeline; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.CompoundProcessor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Pipeline; +import org.elasticsearch.ingest.Processor; import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ESTestCase; import org.junit.Before; @@ -42,9 +42,9 @@ import java.util.Map; import static org.elasticsearch.action.ingest.SimulatePipelineRequest.Fields; import static org.elasticsearch.action.ingest.SimulatePipelineRequest.SIMULATED_PIPELINE_ID; -import static org.elasticsearch.ingest.core.IngestDocument.MetaData.ID; -import static org.elasticsearch.ingest.core.IngestDocument.MetaData.INDEX; -import static org.elasticsearch.ingest.core.IngestDocument.MetaData.TYPE; +import static org.elasticsearch.ingest.IngestDocument.MetaData.ID; +import static org.elasticsearch.ingest.IngestDocument.MetaData.INDEX; +import static org.elasticsearch.ingest.IngestDocument.MetaData.TYPE; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.mock; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java index c8f09a5ba88..1376ca4280e 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulatePipelineResponseTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; @@ -30,7 +30,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; +import static org.elasticsearch.ingest.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.nullValue; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulateProcessorResultTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulateProcessorResultTests.java index 0ee1a5699dc..f612f36c9d6 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateProcessorResultTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateProcessorResultTests.java @@ -22,12 +22,12 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.ingest.RandomDocumentPicks; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.test.ESTestCase; import java.io.IOException; -import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; +import static org.elasticsearch.ingest.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/TrackingResultProcessorTests.java b/core/src/test/java/org/elasticsearch/action/ingest/TrackingResultProcessorTests.java index ac7282051d5..30f17515f00 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/TrackingResultProcessorTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/TrackingResultProcessorTests.java @@ -20,11 +20,9 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.ingest.SimulateProcessorResult; -import org.elasticsearch.action.ingest.TrackingResultProcessor; import org.elasticsearch.ingest.TestProcessor; -import org.elasticsearch.ingest.core.CompoundProcessor; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.CompoundProcessor; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.test.ESTestCase; import org.junit.Before; @@ -34,9 +32,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.elasticsearch.ingest.core.CompoundProcessor.ON_FAILURE_MESSAGE_FIELD; -import static org.elasticsearch.ingest.core.CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD; -import static org.elasticsearch.ingest.core.CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD; +import static org.elasticsearch.ingest.CompoundProcessor.ON_FAILURE_MESSAGE_FIELD; +import static org.elasticsearch.ingest.CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD; +import static org.elasticsearch.ingest.CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD; import static org.elasticsearch.action.ingest.TrackingResultProcessor.decorate; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.nullValue; diff --git a/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java b/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java index 810947c8e0a..a7ce842913d 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.ingest.RandomDocumentPicks; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -34,7 +34,7 @@ import java.util.HashMap; import java.util.Map; import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS; -import static org.elasticsearch.ingest.core.IngestDocumentTests.assertIngestDocument; +import static org.elasticsearch.ingest.IngestDocumentTests.assertIngestDocument; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; diff --git a/core/src/test/java/org/elasticsearch/ingest/core/CompoundProcessorTests.java b/core/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java similarity index 99% rename from core/src/test/java/org/elasticsearch/ingest/core/CompoundProcessorTests.java rename to core/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java index 0e110288597..6cb2c9dd53f 100644 --- a/core/src/test/java/org/elasticsearch/ingest/core/CompoundProcessorTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java @@ -17,10 +17,9 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.ingest.TestProcessor; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/core/src/test/java/org/elasticsearch/ingest/core/ConfigurationUtilsTests.java b/core/src/test/java/org/elasticsearch/ingest/ConfigurationUtilsTests.java similarity index 97% rename from core/src/test/java/org/elasticsearch/ingest/core/ConfigurationUtilsTests.java rename to core/src/test/java/org/elasticsearch/ingest/ConfigurationUtilsTests.java index ff3670b22b2..fa78d5aa16c 100644 --- a/core/src/test/java/org/elasticsearch/ingest/core/ConfigurationUtilsTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/ConfigurationUtilsTests.java @@ -17,14 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.ingest.ProcessorsRegistry; -import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; import org.junit.Before; diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java b/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java index 72856c143e0..b94cc5ca319 100644 --- a/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java +++ b/core/src/test/java/org/elasticsearch/ingest/IngestClientIT.java @@ -37,7 +37,6 @@ import org.elasticsearch.action.ingest.SimulatePipelineResponse; import org.elasticsearch.action.ingest.WritePipelineResponse; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.ingest.core.IngestDocument; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestCloseIT.java b/core/src/test/java/org/elasticsearch/ingest/IngestCloseIT.java index 007338cf918..ed0a302cf73 100644 --- a/core/src/test/java/org/elasticsearch/ingest/IngestCloseIT.java +++ b/core/src/test/java/org/elasticsearch/ingest/IngestCloseIT.java @@ -19,11 +19,9 @@ package org.elasticsearch.ingest; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; import org.elasticsearch.node.NodeModule; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; -import org.junit.After; import java.io.Closeable; import java.io.IOException; diff --git a/core/src/test/java/org/elasticsearch/ingest/core/IngestDocumentTests.java b/core/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java similarity index 99% rename from core/src/test/java/org/elasticsearch/ingest/core/IngestDocumentTests.java rename to core/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java index b706c85afac..ee4da02478d 100644 --- a/core/src/test/java/org/elasticsearch/ingest/core/IngestDocumentTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java @@ -17,10 +17,8 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; -import org.elasticsearch.action.ingest.WriteableIngestDocumentTests; -import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java b/core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java index c6a096f238e..29cf9f97290 100644 --- a/core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java +++ b/core/src/test/java/org/elasticsearch/ingest/IngestProcessorNotInstalledOnAllNodesIT.java @@ -22,7 +22,6 @@ package org.elasticsearch.ingest; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ingest.WritePipelineResponse; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.ingest.core.Pipeline; import org.elasticsearch.node.service.NodeService; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java index 1b96939eb38..d001a829443 100644 --- a/core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/PipelineExecutionServiceTests.java @@ -28,10 +28,6 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.ingest.core.CompoundProcessor; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Pipeline; -import org.elasticsearch.ingest.core.Processor; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.hamcrest.CustomTypeSafeMatcher; diff --git a/core/src/test/java/org/elasticsearch/ingest/core/PipelineFactoryTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineFactoryTests.java similarity index 96% rename from core/src/test/java/org/elasticsearch/ingest/core/PipelineFactoryTests.java rename to core/src/test/java/org/elasticsearch/ingest/PipelineFactoryTests.java index dd12d020247..7c4f8236404 100644 --- a/core/src/test/java/org/elasticsearch/ingest/core/PipelineFactoryTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/PipelineFactoryTests.java @@ -17,17 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.ingest.ProcessorsRegistry; -import org.elasticsearch.ingest.TestProcessor; -import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.threadpool.TestThreadPool; import java.util.Arrays; import java.util.Collections; diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java index 33992af0f67..55ea4360ece 100644 --- a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java @@ -32,11 +32,6 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.LocalTransportAddress; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.IngestInfo; -import org.elasticsearch.ingest.core.Pipeline; -import org.elasticsearch.ingest.core.Processor; -import org.elasticsearch.ingest.core.ProcessorInfo; import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/core/src/test/java/org/elasticsearch/ingest/core/ValueSourceTests.java b/core/src/test/java/org/elasticsearch/ingest/ValueSourceTests.java similarity index 95% rename from core/src/test/java/org/elasticsearch/ingest/core/ValueSourceTests.java rename to core/src/test/java/org/elasticsearch/ingest/ValueSourceTests.java index 57a6eb7ee68..0ac353b4ae8 100644 --- a/core/src/test/java/org/elasticsearch/ingest/core/ValueSourceTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/ValueSourceTests.java @@ -17,10 +17,8 @@ * under the License. */ -package org.elasticsearch.ingest.core; +package org.elasticsearch.ingest; -import org.elasticsearch.ingest.RandomDocumentPicks; -import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; diff --git a/core/src/test/java/org/elasticsearch/nodesinfo/NodeInfoStreamingTests.java b/core/src/test/java/org/elasticsearch/nodesinfo/NodeInfoStreamingTests.java index 92dac4bd784..b30d4c5af7f 100644 --- a/core/src/test/java/org/elasticsearch/nodesinfo/NodeInfoStreamingTests.java +++ b/core/src/test/java/org/elasticsearch/nodesinfo/NodeInfoStreamingTests.java @@ -33,7 +33,7 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.http.HttpInfo; -import org.elasticsearch.ingest.core.IngestInfo; +import org.elasticsearch.ingest.IngestInfo; import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.monitor.os.DummyOsInfo; import org.elasticsearch.monitor.os.OsInfo; diff --git a/modules/ingest-common/build.gradle b/modules/ingest-common/build.gradle index e7935cd2738..6d93f663116 100644 --- a/modules/ingest-common/build.gradle +++ b/modules/ingest-common/build.gradle @@ -19,7 +19,7 @@ esplugin { description 'Module for ingest processors that do not require additional security permissions or have large dependencies and resources' - classname 'org.elasticsearch.ingest.IngestCommonPlugin' + classname 'org.elasticsearch.ingest.common.IngestCommonPlugin' } dependencies { diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/AbstractStringProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AbstractStringProcessor.java similarity index 89% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/AbstractStringProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AbstractStringProcessor.java index 2dc11d43af1..d9ffd34cac1 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/AbstractStringProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AbstractStringProcessor.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.ConfigurationUtils; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import java.util.Map; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/AppendProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AppendProcessor.java similarity index 87% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/AppendProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AppendProcessor.java index 4019f8312ef..af163c3c187 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/AppendProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AppendProcessor.java @@ -17,14 +17,14 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.TemplateService; -import org.elasticsearch.ingest.core.ValueSource; -import org.elasticsearch.ingest.core.ConfigurationUtils; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.TemplateService; +import org.elasticsearch.ingest.ValueSource; import java.util.Map; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/ConvertProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java similarity index 94% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/ConvertProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java index d019ab01ef7..015c56c72c3 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/ConvertProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java @@ -17,19 +17,19 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.ConfigurationUtils; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; -import static org.elasticsearch.ingest.core.ConfigurationUtils.newConfigurationException; +import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationException; /** * Processor that converts fields content to a different type. Supported types are: integer, float, boolean and string. diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateFormat.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java similarity index 98% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateFormat.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java index 2e27bd72cd2..4a97a7e7ab2 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateFormat.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateIndexNameProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateIndexNameProcessor.java similarity index 95% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateIndexNameProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateIndexNameProcessor.java index cad66a3187b..a94d4d048a8 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateIndexNameProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateIndexNameProcessor.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.ConfigurationUtils; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.format.DateTimeFormat; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java similarity index 94% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java index 273b42d2b8c..b82b9c8b76c 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/DateProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.ConfigurationUtils; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.format.ISODateTimeFormat; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/FailProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/FailProcessor.java similarity index 86% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/FailProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/FailProcessor.java index 2e0b79501e0..6c434d85d5a 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/FailProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/FailProcessor.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.ConfigurationUtils; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.TemplateService; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.TemplateService; import java.util.Map; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/FailProcessorException.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/FailProcessorException.java similarity index 79% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/FailProcessorException.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/FailProcessorException.java index bd010b1423c..9add5c5762f 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/FailProcessorException.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/FailProcessorException.java @@ -17,13 +17,16 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; + +import org.elasticsearch.ingest.CompoundProcessor; +import org.elasticsearch.ingest.IngestDocument; /** * Exception class thrown by {@link FailProcessor}. * - * This exception is caught in the {@link org.elasticsearch.ingest.core.CompoundProcessor} and - * then changes the state of {@link org.elasticsearch.ingest.core.IngestDocument}. This + * This exception is caught in the {@link CompoundProcessor} and + * then changes the state of {@link IngestDocument}. This * exception should get serialized. */ public class FailProcessorException extends RuntimeException { diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/ForEachProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ForEachProcessor.java similarity index 87% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/ForEachProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ForEachProcessor.java index 2ca895779af..b6d14d1b8c5 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/ForEachProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ForEachProcessor.java @@ -17,13 +17,14 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.ConfigurationUtils; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.ProcessorsRegistry; import java.util.ArrayList; import java.util.Collections; @@ -31,8 +32,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readList; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readStringProperty; +import static org.elasticsearch.ingest.ConfigurationUtils.readList; +import static org.elasticsearch.ingest.ConfigurationUtils.readStringProperty; /** * A processor that for each value in a list executes a one or more processors. diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/Grok.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/Grok.java similarity index 99% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/Grok.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/Grok.java index 7e5d1e6b516..b6e1877d3e0 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/Grok.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/Grok.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.jcodings.specific.UTF8Encoding; import org.joni.Matcher; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/GrokMatchGroup.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokMatchGroup.java similarity index 97% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/GrokMatchGroup.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokMatchGroup.java index 6fd979f179a..35f8fd312ff 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/GrokMatchGroup.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokMatchGroup.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; final class GrokMatchGroup { private static final String DEFAULT_TYPE = "string"; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/GrokProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessor.java similarity index 94% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/GrokProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessor.java index b709df6e7d4..aa9fbb905cc 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/GrokProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessor.java @@ -17,19 +17,19 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.ConfigurationUtils; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import static org.elasticsearch.ingest.core.ConfigurationUtils.newConfigurationException; +import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationException; public final class GrokProcessor extends AbstractProcessor { diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/GsubProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GsubProcessor.java similarity index 89% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/GsubProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GsubProcessor.java index 8b17766f845..72bc9e76710 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/GsubProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GsubProcessor.java @@ -17,18 +17,18 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.IngestDocument; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static org.elasticsearch.ingest.core.ConfigurationUtils.newConfigurationException; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readStringProperty; +import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationException; +import static org.elasticsearch.ingest.ConfigurationUtils.readStringProperty; /** * Processor that allows to search for patterns in field content and replace them with corresponding string replacement. diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/IngestCommonPlugin.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java similarity index 99% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/IngestCommonPlugin.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java index 92112a37b96..821e47b85bc 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/IngestCommonPlugin.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.node.NodeModule; import org.elasticsearch.plugins.Plugin; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/JoinProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/JoinProcessor.java similarity index 90% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/JoinProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/JoinProcessor.java index 7db5e00b145..8114d20f28f 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/JoinProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/JoinProcessor.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.ConfigurationUtils; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import java.util.List; import java.util.Map; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/LowercaseProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/LowercaseProcessor.java similarity index 97% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/LowercaseProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/LowercaseProcessor.java index 8d5aebcf115..9f8ea7a5614 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/LowercaseProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/LowercaseProcessor.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import java.util.Locale; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/RemoveProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RemoveProcessor.java similarity index 86% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/RemoveProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RemoveProcessor.java index 6670c462d6f..98c4e18a408 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/RemoveProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RemoveProcessor.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.TemplateService; -import org.elasticsearch.ingest.core.ConfigurationUtils; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.TemplateService; import java.util.Map; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/RenameProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RenameProcessor.java similarity index 91% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/RenameProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RenameProcessor.java index 4a6e8bf3ae5..9143321c4aa 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/RenameProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RenameProcessor.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.ConfigurationUtils; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import java.util.Map; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/ScriptProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java similarity index 91% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/ScriptProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java index 9051ffe408e..6ce85f8a6bf 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/ScriptProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; @@ -35,9 +35,9 @@ import java.util.Map; import static java.util.Collections.emptyMap; import static org.elasticsearch.common.Strings.hasLength; -import static org.elasticsearch.ingest.core.ConfigurationUtils.newConfigurationException; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readOptionalStringProperty; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readStringProperty; +import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationException; +import static org.elasticsearch.ingest.ConfigurationUtils.readOptionalStringProperty; +import static org.elasticsearch.ingest.ConfigurationUtils.readStringProperty; import static org.elasticsearch.script.ScriptService.ScriptType.FILE; import static org.elasticsearch.script.ScriptService.ScriptType.INLINE; import static org.elasticsearch.script.ScriptService.ScriptType.STORED; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/SetProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SetProcessor.java similarity index 89% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/SetProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SetProcessor.java index 6f576dcafc0..a78701645a9 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/SetProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SetProcessor.java @@ -17,14 +17,14 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.TemplateService; -import org.elasticsearch.ingest.core.ValueSource; -import org.elasticsearch.ingest.core.ConfigurationUtils; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.TemplateService; +import org.elasticsearch.ingest.ValueSource; import java.util.Map; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/SortProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java similarity index 93% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/SortProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java index ee708d97d47..706a1cef9c5 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/SortProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.ConfigurationUtils; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import java.util.Collections; import java.util.List; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/SplitProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SplitProcessor.java similarity index 90% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/SplitProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SplitProcessor.java index 2d43cae3f09..f7c5e8befc4 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/SplitProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SplitProcessor.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.ConfigurationUtils; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.ConfigurationUtils; +import org.elasticsearch.ingest.IngestDocument; import java.util.ArrayList; import java.util.Collections; diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/TrimProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/TrimProcessor.java similarity index 97% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/TrimProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/TrimProcessor.java index 294cd59265f..a57a25125d6 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/TrimProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/TrimProcessor.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; /** * Processor that trims the content of string fields. diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/UppercaseProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/UppercaseProcessor.java similarity index 97% rename from modules/ingest-common/src/main/java/org/elasticsearch/ingest/UppercaseProcessor.java rename to modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/UppercaseProcessor.java index cd51f0dbc71..a5c817352a1 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/UppercaseProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/UppercaseProcessor.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import java.util.Locale; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/AbstractStringProcessorTestCase.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AbstractStringProcessorTestCase.java similarity index 95% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/AbstractStringProcessorTestCase.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AbstractStringProcessorTestCase.java index b1f517b3d88..e987510f25a 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/AbstractStringProcessorTestCase.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AbstractStringProcessorTestCase.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; import java.util.Collections; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/AppendProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AppendProcessorFactoryTests.java similarity index 95% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/AppendProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AppendProcessorFactoryTests.java index 884bbb7903a..fbf77cc4285 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/AppendProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AppendProcessorFactoryTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/AppendProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AppendProcessorTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/AppendProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AppendProcessorTests.java index 63a1bb9cce2..16df08721d3 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/AppendProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AppendProcessorTests.java @@ -17,12 +17,14 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.TemplateService; -import org.elasticsearch.ingest.core.ValueSource; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; +import org.elasticsearch.ingest.TemplateService; +import org.elasticsearch.ingest.TestTemplateService; +import org.elasticsearch.ingest.ValueSource; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ConvertProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ConvertProcessorFactoryTests.java similarity index 97% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/ConvertProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ConvertProcessorFactoryTests.java index ce043f6aed4..1ec5362af14 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ConvertProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ConvertProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import org.hamcrest.Matchers; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ConvertProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ConvertProcessorTests.java similarity index 98% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/ConvertProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ConvertProcessorTests.java index f9ec7883190..02f859ecfa5 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ConvertProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ConvertProcessorTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; @@ -30,7 +31,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import static org.elasticsearch.ingest.ConvertProcessor.Type; +import static org.elasticsearch.ingest.common.ConvertProcessor.Type; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.sameInstance; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateFormatTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateFormatTests.java similarity index 98% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateFormatTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateFormatTests.java index 8fcff4789c7..0885371f867 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateFormatTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateFormatTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.test.ESTestCase; import org.joda.time.DateTime; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateIndexNameFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateIndexNameFactoryTests.java similarity index 99% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateIndexNameFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateIndexNameFactoryTests.java index d6b5f7a0ff7..42877236b88 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateIndexNameFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateIndexNameFactoryTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.test.ESTestCase; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateIndexNameProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateIndexNameProcessorTests.java similarity index 97% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateIndexNameProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateIndexNameProcessorTests.java index 3baa3d3ac7c..c546f021823 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateIndexNameProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateIndexNameProcessorTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.test.ESTestCase; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateProcessorFactoryTests.java similarity index 98% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateProcessorFactoryTests.java index 9933f3fbb65..65dcdf6082c 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import org.joda.time.DateTimeZone; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateProcessorTests.java similarity index 98% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateProcessorTests.java index 2d32282d332..768f402ee4b 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/DateProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateProcessorTests.java @@ -17,9 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/FailProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/FailProcessorFactoryTests.java similarity index 93% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/FailProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/FailProcessorFactoryTests.java index 1f1e9c72b12..db16b78b316 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/FailProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/FailProcessorFactoryTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/FailProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/FailProcessorTests.java similarity index 86% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/FailProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/FailProcessorTests.java index 457aaf45c66..76685854d21 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/FailProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/FailProcessorTests.java @@ -17,10 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; +import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.test.ESTestCase; import static org.hamcrest.Matchers.equalTo; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ForEachProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorFactoryTests.java similarity index 94% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/ForEachProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorFactoryTests.java index 161b50c5e4c..d45e98ab06a 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ForEachProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorFactoryTests.java @@ -17,10 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.ProcessorsRegistry; +import org.elasticsearch.ingest.TestProcessor; import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ESTestCase; import org.hamcrest.Matchers; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ForEachProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorTests.java similarity index 95% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/ForEachProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorTests.java index 19f1e15f09e..05287935b49 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ForEachProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorTests.java @@ -17,13 +17,15 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.CompoundProcessor; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; -import org.elasticsearch.ingest.core.TemplateService; -import org.elasticsearch.ingest.core.ValueSource; +import org.elasticsearch.ingest.CompoundProcessor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.TemplateService; +import org.elasticsearch.ingest.TestProcessor; +import org.elasticsearch.ingest.TestTemplateService; +import org.elasticsearch.ingest.ValueSource; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokProcessorFactoryTests.java similarity index 98% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokProcessorFactoryTests.java index 374a15f4f25..a7a133b4363 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.Collections; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokProcessorTests.java similarity index 98% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokProcessorTests.java index 919cd5ca548..f108e80e790 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokProcessorTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.RandomDocumentPicks; -import org.elasticsearch.ingest.core.IngestDocument; import org.elasticsearch.test.ESTestCase; import java.util.Arrays; @@ -29,7 +29,6 @@ import java.util.HashMap; import java.util.Map; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; public class GrokProcessorTests extends ESTestCase { diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokTests.java similarity index 99% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokTests.java index fd757c4962c..e8b88ea0d12 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GrokTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GrokTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GsubProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GsubProcessorFactoryTests.java similarity index 97% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/GsubProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GsubProcessorFactoryTests.java index f840576e522..60cceb34024 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GsubProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GsubProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GsubProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GsubProcessorTests.java similarity index 95% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/GsubProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GsubProcessorTests.java index 066609f5e3a..20dc5b8c8de 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/GsubProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/GsubProcessorTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; import java.util.Collections; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/IngestCommonRestIT.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonRestIT.java similarity index 97% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/IngestCommonRestIT.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonRestIT.java index 544e47b8e94..94418ac552c 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/IngestCommonRestIT.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonRestIT.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/JoinProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/JoinProcessorFactoryTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/JoinProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/JoinProcessorFactoryTests.java index 45e643579a4..970fd8b8b9a 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/JoinProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/JoinProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/JoinProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/JoinProcessorTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/JoinProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/JoinProcessorTests.java index 39906fb4850..078d6365709 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/JoinProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/JoinProcessorTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/LowercaseProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/LowercaseProcessorFactoryTests.java similarity index 95% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/LowercaseProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/LowercaseProcessorFactoryTests.java index b7a315b176b..4dec115458c 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/LowercaseProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/LowercaseProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/LowercaseProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/LowercaseProcessorTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/LowercaseProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/LowercaseProcessorTests.java index 81e23ef4689..413b3f64650 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/LowercaseProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/LowercaseProcessorTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import java.util.Locale; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/RemoveProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorFactoryTests.java similarity index 93% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/RemoveProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorFactoryTests.java index 672058b61e4..a5f88103e96 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/RemoveProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorFactoryTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/RemoveProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java similarity index 90% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/RemoveProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java index abc68aa60b6..fd569567d1a 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/RemoveProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java @@ -17,10 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; +import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/RenameProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RenameProcessorFactoryTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/RenameProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RenameProcessorFactoryTests.java index 005abb8c0d0..c078f09dd92 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/RenameProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RenameProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/RenameProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RenameProcessorTests.java similarity index 97% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/RenameProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RenameProcessorTests.java index 85faca03e9c..dc4f7328791 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/RenameProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RenameProcessorTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ScriptProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java similarity index 98% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/ScriptProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java index e5cd4d3699e..59a5d7ceaa2 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ScriptProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.service.ClusterService; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ScriptProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorTests.java similarity index 95% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/ScriptProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorTests.java index 377b93ef454..6da127a798b 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/ScriptProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SetProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/SetProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java index acb09b0c96f..b8c97a379cb 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SetProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.TestTemplateService; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SetProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorTests.java similarity index 94% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/SetProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorTests.java index 1d28124d55a..9ef8fa44ac9 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SetProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorTests.java @@ -17,12 +17,14 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.TemplateService; -import org.elasticsearch.ingest.core.ValueSource; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; +import org.elasticsearch.ingest.TemplateService; +import org.elasticsearch.ingest.TestTemplateService; +import org.elasticsearch.ingest.ValueSource; import org.elasticsearch.test.ESTestCase; import org.hamcrest.Matchers; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SortProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SortProcessorTests.java similarity index 98% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/SortProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SortProcessorTests.java index 40da784bf34..97352109e2c 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SortProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SortProcessorTests.java @@ -17,11 +17,12 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; -import org.elasticsearch.ingest.SortProcessor.SortOrder; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; +import org.elasticsearch.ingest.common.SortProcessor.SortOrder; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SplitProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SplitProcessorFactoryTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/SplitProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SplitProcessorFactoryTests.java index 7d0c3c4d970..c747807b710 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SplitProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SplitProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SplitProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SplitProcessorTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/SplitProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SplitProcessorTests.java index 95bb4fe4109..13d45dc126b 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/SplitProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SplitProcessorTests.java @@ -17,10 +17,11 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; +import org.elasticsearch.ingest.IngestDocument; +import org.elasticsearch.ingest.Processor; +import org.elasticsearch.ingest.RandomDocumentPicks; import org.elasticsearch.test.ESTestCase; import java.util.Arrays; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/TrimProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/TrimProcessorFactoryTests.java similarity index 95% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/TrimProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/TrimProcessorFactoryTests.java index 0692d53c9e3..54904775478 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/TrimProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/TrimProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/TrimProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/TrimProcessorTests.java similarity index 97% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/TrimProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/TrimProcessorTests.java index ce51dea3acb..4b776a2ee84 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/TrimProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/TrimProcessorTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; public class TrimProcessorTests extends AbstractStringProcessorTestCase { diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/UppercaseProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/UppercaseProcessorFactoryTests.java similarity index 95% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/UppercaseProcessorFactoryTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/UppercaseProcessorFactoryTests.java index 0b5eafd2173..cd4d1faf767 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/UppercaseProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/UppercaseProcessorFactoryTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/UppercaseProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/UppercaseProcessorTests.java similarity index 96% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/UppercaseProcessorTests.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/UppercaseProcessorTests.java index 6881d117946..ff8dc16b6e2 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/UppercaseProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/UppercaseProcessorTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.ingest; +package org.elasticsearch.ingest.common; import java.util.Locale; diff --git a/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java b/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java index d47e03dcbfe..40ebe2592ab 100644 --- a/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java +++ b/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java @@ -24,9 +24,9 @@ import org.apache.tika.metadata.Metadata; import org.apache.tika.metadata.TikaCoreProperties; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Strings; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.IngestDocument; import java.io.IOException; import java.util.Arrays; @@ -37,10 +37,10 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import static org.elasticsearch.ingest.core.ConfigurationUtils.newConfigurationException; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readIntProperty; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readOptionalList; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readStringProperty; +import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationException; +import static org.elasticsearch.ingest.ConfigurationUtils.readIntProperty; +import static org.elasticsearch.ingest.ConfigurationUtils.readOptionalList; +import static org.elasticsearch.ingest.ConfigurationUtils.readStringProperty; public final class AttachmentProcessor extends AbstractProcessor { diff --git a/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorFactoryTests.java b/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorFactoryTests.java index 09fb4e3951d..6bd4e07702e 100644 --- a/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorFactoryTests.java +++ b/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorFactoryTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.ingest.attachment; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; diff --git a/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorTests.java b/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorTests.java index 56e72be351e..4e051d05724 100644 --- a/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorTests.java +++ b/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorTests.java @@ -22,7 +22,7 @@ package org.elasticsearch.ingest.attachment; import org.apache.commons.io.IOUtils; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ingest.RandomDocumentPicks; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.test.ESTestCase; import org.junit.Before; diff --git a/plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java b/plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java index 9d606419e57..c29bf4aa65d 100644 --- a/plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java +++ b/plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java @@ -33,9 +33,9 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.SpecialPermission; import org.elasticsearch.common.network.InetAddresses; import org.elasticsearch.common.network.NetworkAddress; -import org.elasticsearch.ingest.core.AbstractProcessor; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.AbstractProcessor; +import org.elasticsearch.ingest.AbstractProcessorFactory; +import org.elasticsearch.ingest.IngestDocument; import java.io.Closeable; import java.io.IOException; @@ -51,9 +51,9 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import static org.elasticsearch.ingest.core.ConfigurationUtils.newConfigurationException; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readOptionalList; -import static org.elasticsearch.ingest.core.ConfigurationUtils.readStringProperty; +import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationException; +import static org.elasticsearch.ingest.ConfigurationUtils.readOptionalList; +import static org.elasticsearch.ingest.ConfigurationUtils.readStringProperty; public final class GeoIpProcessor extends AbstractProcessor { @@ -96,7 +96,8 @@ public final class GeoIpProcessor extends AbstractProcessor { } break; default: - throw new ElasticsearchParseException("Unsupported database type [" + dbReader.getMetadata().getDatabaseType() + "]", new IllegalStateException()); + throw new ElasticsearchParseException("Unsupported database type [" + dbReader.getMetadata().getDatabaseType() + + "]", new IllegalStateException()); } ingestDocument.setFieldValue(targetField, geoData); } @@ -259,7 +260,8 @@ public final class GeoIpProcessor extends AbstractProcessor { } else if (COUNTRY_DB_TYPE.equals(databaseType)) { properties = DEFAULT_COUNTRY_PROPERTIES; } else { - throw newConfigurationException(TYPE, processorTag, "database_file", "Unsupported database type [" + databaseType + "]"); + throw newConfigurationException(TYPE, processorTag, "database_file", "Unsupported database type [" + + databaseType + "]"); } } @@ -312,7 +314,8 @@ public final class GeoIpProcessor extends AbstractProcessor { } return property; } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("illegal property value [" + value + "]. valid values are " + Arrays.toString(validProperties.toArray())); + throw new IllegalArgumentException("illegal property value [" + value + "]. valid values are " + + Arrays.toString(validProperties.toArray())); } } } diff --git a/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorFactoryTests.java b/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorFactoryTests.java index 25d8f1f6f5f..04729162729 100644 --- a/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorFactoryTests.java +++ b/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorFactoryTests.java @@ -23,7 +23,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.maxmind.geoip2.DatabaseReader; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Randomness; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; +import org.elasticsearch.ingest.AbstractProcessorFactory; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.StreamsUtils; import org.junit.AfterClass; @@ -54,8 +54,10 @@ public class GeoIpProcessorFactoryTests extends ESTestCase { Path configDir = createTempDir(); Path geoIpConfigDir = configDir.resolve("ingest-geoip"); Files.createDirectories(geoIpConfigDir); - Files.copy(new ByteArrayInputStream(StreamsUtils.copyToBytesFromClasspath("/GeoLite2-City.mmdb.gz")), geoIpConfigDir.resolve("GeoLite2-City.mmdb.gz")); - Files.copy(new ByteArrayInputStream(StreamsUtils.copyToBytesFromClasspath("/GeoLite2-Country.mmdb.gz")), geoIpConfigDir.resolve("GeoLite2-Country.mmdb.gz")); + Files.copy(new ByteArrayInputStream(StreamsUtils.copyToBytesFromClasspath("/GeoLite2-City.mmdb.gz")), + geoIpConfigDir.resolve("GeoLite2-City.mmdb.gz")); + Files.copy(new ByteArrayInputStream(StreamsUtils.copyToBytesFromClasspath("/GeoLite2-Country.mmdb.gz")), + geoIpConfigDir.resolve("GeoLite2-Country.mmdb.gz")); databaseReaders = IngestGeoIpPlugin.loadDatabaseReaders(geoIpConfigDir); } @@ -136,7 +138,8 @@ public class GeoIpProcessorFactoryTests extends ESTestCase { factory.create(config); fail("Exception expected"); } catch (ElasticsearchParseException e) { - assertThat(e.getMessage(), equalTo("[properties] illegal property value [" + cityProperty + "]. valid values are [IP, COUNTRY_ISO_CODE, COUNTRY_NAME, CONTINENT_NAME]")); + assertThat(e.getMessage(), equalTo("[properties] illegal property value [" + cityProperty + + "]. valid values are [IP, COUNTRY_ISO_CODE, COUNTRY_NAME, CONTINENT_NAME]")); } } @@ -183,7 +186,8 @@ public class GeoIpProcessorFactoryTests extends ESTestCase { factory.create(config); fail("exception expected"); } catch (ElasticsearchParseException e) { - assertThat(e.getMessage(), equalTo("[properties] illegal property value [invalid]. valid values are [IP, COUNTRY_ISO_CODE, COUNTRY_NAME, CONTINENT_NAME, REGION_NAME, CITY_NAME, TIMEZONE, LOCATION]")); + assertThat(e.getMessage(), equalTo("[properties] illegal property value [invalid]. valid values are [IP, COUNTRY_ISO_CODE, " + + "COUNTRY_NAME, CONTINENT_NAME, REGION_NAME, CITY_NAME, TIMEZONE, LOCATION]")); } config = new HashMap<>(); diff --git a/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java b/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java index a64a42fa95e..f3141c735d2 100644 --- a/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java +++ b/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.ingest.geoip; import com.maxmind.geoip2.DatabaseReader; import org.elasticsearch.ingest.RandomDocumentPicks; -import org.elasticsearch.ingest.core.IngestDocument; +import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -38,7 +38,8 @@ public class GeoIpProcessorTests extends ESTestCase { public void testCity() throws Exception { InputStream database = getDatabaseFileInputStream("/GeoLite2-City.mmdb.gz"); - GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); + GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", + new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); Map document = new HashMap<>(); document.put("source_field", "8.8.8.8"); @@ -64,7 +65,8 @@ public class GeoIpProcessorTests extends ESTestCase { public void testCountry() throws Exception { InputStream database = getDatabaseFileInputStream("/GeoLite2-Country.mmdb.gz"); - GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); + GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", + new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); Map document = new HashMap<>(); document.put("source_field", "82.170.213.79"); @@ -83,7 +85,8 @@ public class GeoIpProcessorTests extends ESTestCase { public void testAddressIsNotInTheDatabase() throws Exception { InputStream database = getDatabaseFileInputStream("/GeoLite2-City.mmdb.gz"); - GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); + GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", + new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); Map document = new HashMap<>(); document.put("source_field", "127.0.0.1"); @@ -97,7 +100,8 @@ public class GeoIpProcessorTests extends ESTestCase { /** Don't silently do DNS lookups or anything trappy on bogus data */ public void testInvalid() throws Exception { InputStream database = getDatabaseFileInputStream("/GeoLite2-City.mmdb.gz"); - GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); + GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field", + new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class)); Map document = new HashMap<>(); document.put("source_field", "www.google.com"); diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/AbstractScriptTestCase.java b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/AbstractScriptTestCase.java index 77f09d4df37..1c60a32e883 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/AbstractScriptTestCase.java +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/AbstractScriptTestCase.java @@ -21,7 +21,6 @@ package org.elasticsearch.ingest; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.ingest.core.TemplateService; import org.elasticsearch.script.ScriptContextRegistry; import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptService; diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/IngestDocumentMustacheIT.java b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/IngestDocumentMustacheIT.java index 112f44b9f2c..345ccb0ddcd 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/IngestDocumentMustacheIT.java +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/IngestDocumentMustacheIT.java @@ -19,9 +19,6 @@ package org.elasticsearch.ingest; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.ValueSource; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/TemplateServiceIT.java b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/TemplateServiceIT.java index 98b215110b1..c13058311bb 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/TemplateServiceIT.java +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/TemplateServiceIT.java @@ -19,8 +19,6 @@ package org.elasticsearch.ingest; -import org.elasticsearch.ingest.core.TemplateService; - import java.util.Collections; import java.util.HashMap; import java.util.Map; diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/ValueSourceMustacheIT.java b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/ValueSourceMustacheIT.java index 854b615e9bb..884897885ca 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/ValueSourceMustacheIT.java +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/ingest/ValueSourceMustacheIT.java @@ -19,9 +19,6 @@ package org.elasticsearch.ingest; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.ValueSource; - import java.util.Arrays; import java.util.Collections; import java.util.HashMap; diff --git a/test/framework/src/main/java/org/elasticsearch/ingest/RandomDocumentPicks.java b/test/framework/src/main/java/org/elasticsearch/ingest/RandomDocumentPicks.java index 6dc920c6ff8..3be4cd3edf4 100644 --- a/test/framework/src/main/java/org/elasticsearch/ingest/RandomDocumentPicks.java +++ b/test/framework/src/main/java/org/elasticsearch/ingest/RandomDocumentPicks.java @@ -22,7 +22,6 @@ package org.elasticsearch.ingest; import com.carrotsearch.randomizedtesting.generators.RandomInts; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.carrotsearch.randomizedtesting.generators.RandomStrings; -import org.elasticsearch.ingest.core.IngestDocument; import java.util.ArrayList; import java.util.HashMap; diff --git a/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java b/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java index ae13174e7c1..e36d73a8d9f 100644 --- a/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java +++ b/test/framework/src/main/java/org/elasticsearch/ingest/TestProcessor.java @@ -19,10 +19,6 @@ package org.elasticsearch.ingest; -import org.elasticsearch.ingest.core.AbstractProcessorFactory; -import org.elasticsearch.ingest.core.IngestDocument; -import org.elasticsearch.ingest.core.Processor; - import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; diff --git a/test/framework/src/main/java/org/elasticsearch/ingest/TestTemplateService.java b/test/framework/src/main/java/org/elasticsearch/ingest/TestTemplateService.java index 9330db1bfcb..d44764fa8ac 100644 --- a/test/framework/src/main/java/org/elasticsearch/ingest/TestTemplateService.java +++ b/test/framework/src/main/java/org/elasticsearch/ingest/TestTemplateService.java @@ -19,8 +19,6 @@ package org.elasticsearch.ingest; -import org.elasticsearch.ingest.core.TemplateService; - import java.util.Map; public class TestTemplateService implements TemplateService { From 423291b6bcdafd736c749ff8eb14bc578d37b6d3 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 17 Jun 2016 19:08:40 +0200 Subject: [PATCH 80/87] Change default similarity to BM25 The default similarity was set to `classic` which refers to TFIDF and has not been moved after the upgrade to Lucene 6. Though moving to BM25 could have some downside for queries that relies on coordination factor (match_query, multi_match_query) ? relates #18944 --- .../index/similarity/SimilarityService.java | 6 ++-- .../similarity/SimilarityServiceTests.java | 16 +++++++-- .../index-modules/similarity.asciidoc | 34 +++++++++---------- .../migration/migrate_5_0/search.asciidoc | 4 +++ 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java b/core/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java index 865c0eb685b..4ba2e0d0a38 100644 --- a/core/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java +++ b/core/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java @@ -36,7 +36,7 @@ import java.util.function.BiFunction; public final class SimilarityService extends AbstractIndexComponent { - public final static String DEFAULT_SIMILARITY = "classic"; + public final static String DEFAULT_SIMILARITY = "BM25"; private final Similarity defaultSimilarity; private final Similarity baseSimilarity; private final Map similarities; @@ -121,8 +121,8 @@ public final class SimilarityService extends AbstractIndexComponent { return similarities.get(name); } - public SimilarityProvider getDefaultSimilarity() { - return similarities.get("default"); + Similarity getDefaultSimilarity() { + return defaultSimilarity; } static class PerFieldSimilarity extends PerFieldSimilarityWrapper { diff --git a/core/src/test/java/org/elasticsearch/index/similarity/SimilarityServiceTests.java b/core/src/test/java/org/elasticsearch/index/similarity/SimilarityServiceTests.java index edb337fd4e6..57d025128d8 100644 --- a/core/src/test/java/org/elasticsearch/index/similarity/SimilarityServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/similarity/SimilarityServiceTests.java @@ -18,6 +18,8 @@ */ package org.elasticsearch.index.similarity; +import org.apache.lucene.search.similarities.BM25Similarity; +import org.apache.lucene.search.similarities.ClassicSimilarity; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; @@ -27,7 +29,15 @@ import org.elasticsearch.test.IndexSettingsModule; import java.util.Collections; +import static org.hamcrest.Matchers.instanceOf; + public class SimilarityServiceTests extends ESTestCase { + public void testDefaultSimilarity() { + Settings settings = Settings.builder().build(); + IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", settings); + SimilarityService service = new SimilarityService(indexSettings, Collections.emptyMap()); + assertThat(service.getDefaultSimilarity(), instanceOf(BM25Similarity.class)); + } // Tests #16594 public void testOverrideBuiltInSimilarity() { @@ -53,10 +63,10 @@ public class SimilarityServiceTests extends ESTestCase { } // Tests #16594 - public void testDefaultSimilarity() { - Settings settings = Settings.builder().put("index.similarity.default.type", "BM25").build(); + public void testOverrideDefaultSimilarity() { + Settings settings = Settings.builder().put("index.similarity.default.type", "classic").build(); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", settings); SimilarityService service = new SimilarityService(indexSettings, Collections.emptyMap()); - assertTrue(service.getDefaultSimilarity() instanceof BM25SimilarityProvider); + assertTrue(service.getDefaultSimilarity() instanceof ClassicSimilarity); } } diff --git a/docs/reference/index-modules/similarity.asciidoc b/docs/reference/index-modules/similarity.asciidoc index f1250ddf6c1..1833b45a9ba 100644 --- a/docs/reference/index-modules/similarity.asciidoc +++ b/docs/reference/index-modules/similarity.asciidoc @@ -47,25 +47,11 @@ Here we configure the DFRSimilarity so it can be referenced as [float] === Available similarities -[float] -[[classic-similarity]] -==== Classic similarity - -The classic similarity that is based on the TF/IDF model. This -similarity has the following option: - -`discount_overlaps`:: - Determines whether overlap tokens (Tokens with - 0 position increment) are ignored when computing norm. By default this - is true, meaning overlap tokens do not count when computing norms. - -Type name: `classic` - [float] [[bm25]] -==== BM25 similarity +==== BM25 similarity (*default*) -Another TF/IDF based similarity that has built-in tf normalization and +TF/IDF based similarity that has built-in tf normalization and is supposed to work better for short fields (like names). See http://en.wikipedia.org/wiki/Okapi_BM25[Okapi_BM25] for more details. This similarity has the following options: @@ -86,6 +72,20 @@ This similarity has the following options: Type name: `BM25` +[float] +[[classic-similarity]] +==== Classic similarity + +The classic similarity that is based on the TF/IDF model. This +similarity has the following option: + +`discount_overlaps`:: + Determines whether overlap tokens (Tokens with + 0 position increment) are ignored when computing norm. By default this + is true, meaning overlap tokens do not count when computing norms. + +Type name: `classic` + [float] [[drf]] ==== DFR similarity @@ -178,5 +178,5 @@ You can change the default similarity for all fields by putting the following se [source,js] -------------------------------------------------- -index.similarity.default.type: BM25 +index.similarity.default.type: classic -------------------------------------------------- diff --git a/docs/reference/migration/migrate_5_0/search.asciidoc b/docs/reference/migration/migrate_5_0/search.asciidoc index 7ebd79e66ca..bb42bc20de5 100644 --- a/docs/reference/migration/migrate_5_0/search.asciidoc +++ b/docs/reference/migration/migrate_5_0/search.asciidoc @@ -196,3 +196,7 @@ The <> `_prefer_node` has been superseded by `_prefer_nodes`. By specifying a single node, `_prefer_nodes` provides the same functionality as `_prefer_node` but also supports specifying multiple nodes. + +==== Default similarity + +The default similarity has been changed to `BM25`. From 9d685f6876abc0434ac46fcfdbdfe0cc6f3a3e0f Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Tue, 21 Jun 2016 12:05:44 +0200 Subject: [PATCH 81/87] Fix ut: remap default to classic similarity for indices created before 5.0. --- .../java/org/elasticsearch/index/mapper/core/TypeParsers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java b/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java index 8e6b538a2ae..3ada93acccb 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java @@ -445,7 +445,7 @@ public class TypeParsers { private static SimilarityProvider resolveSimilarity(Mapper.TypeParser.ParserContext parserContext, String name, String value) { if (parserContext.indexVersionCreated().before(Version.V_5_0_0_alpha1) && "default".equals(value)) { // "default" similarity has been renamed into "classic" in 3.x. - value = SimilarityService.DEFAULT_SIMILARITY; + value = "classic"; } SimilarityProvider similarityProvider = parserContext.getSimilarity(value); if (similarityProvider == null) { From 8d5a5e500a70a68c31546d3d69a502dd46a51ddb Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Tue, 21 Jun 2016 16:50:23 +0530 Subject: [PATCH 82/87] file is -> file name (#18994) --- docs/reference/index-modules/slowlog.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/index-modules/slowlog.asciidoc b/docs/reference/index-modules/slowlog.asciidoc index 9ae78b36d28..217a55fb0b9 100644 --- a/docs/reference/index-modules/slowlog.asciidoc +++ b/docs/reference/index-modules/slowlog.asciidoc @@ -58,7 +58,7 @@ index_search_slow_log_file: === Index Slow log The indexing slow log, similar in functionality to the search slow -log. The log file is ends with `_index_indexing_slowlog.log`. Log and +log. The log file name ends with `_index_indexing_slowlog.log`. Log and the thresholds are configured in the elasticsearch.yml file in the same way as the search slowlog. Index slowlog sample: From 3748abfd7a8864ff31a3fe8a90db44317ac04e9c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 21 Jun 2016 07:38:31 -0400 Subject: [PATCH 83/87] Clarify building from sources docs in README This commit clarifies a few issues with the building from sources docs in the README: - modifies Gradle link to use https - version 2.13 of Gradle is required - the command "gradle assemble" is the preferred way to only create a distribution - fixes the specified location of the built distributions Closes #18991 --- README.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.textile b/README.textile index d9549e5eb3c..69d3fd54767 100644 --- a/README.textile +++ b/README.textile @@ -200,11 +200,11 @@ We have just covered a very small portion of what Elasticsearch is all about. Fo h3. Building from Source -Elasticsearch uses "Gradle":http://gradle.org for its build system. You'll need to have a modern version of Gradle installed - 2.8 should do. +Elasticsearch uses "Gradle":https://gradle.org for its build system. You'll need to have a modern version of Gradle installed - 2.13 should do. -In order to create a distribution, simply run the @gradle build@ command in the cloned directory. +In order to create a distribution, simply run the @gradle assemble@ command in the cloned directory. -The distribution for each project will be created under the @target/releases@ directory in that project. +The distribution for each project will be created under the @build/distributions@ directory in that project. See the "TESTING":TESTING.asciidoc file for more information about running the Elasticsearch test suite. From 5ad2fdaa8e13f95020a1fdfb2e007d185bf733ab Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 21 Jun 2016 13:59:11 +0200 Subject: [PATCH 84/87] inner_hits: Don't include `_id`, `_type` and `_index` keys in search response for inner hits Closes #18091 --- .../search/internal/InternalSearchHit.java | 11 +-- .../migration/migrate_5_0/search.asciidoc | 3 + .../search/request/inner-hits.asciidoc | 2 - .../test/search.inner_hits/10_basic.yaml | 84 +++++++++++++++++++ 4 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yaml diff --git a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java index f67ed51b226..389b1ec89b6 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java +++ b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java @@ -439,13 +439,14 @@ public class InternalSearchHit implements SearchHit { builder.field("_shard", shard.shardId()); builder.field("_node", shard.nodeIdText()); } - if (shard != null) { - builder.field(Fields._INDEX, shard.indexText()); - } - builder.field(Fields._TYPE, type); - builder.field(Fields._ID, id); if (nestedIdentity != null) { nestedIdentity.toXContent(builder, params); + } else { + if (shard != null) { + builder.field(Fields._INDEX, shard.indexText()); + } + builder.field(Fields._TYPE, type); + builder.field(Fields._ID, id); } if (version != -1) { builder.field(Fields._VERSION, version); diff --git a/docs/reference/migration/migrate_5_0/search.asciidoc b/docs/reference/migration/migrate_5_0/search.asciidoc index bb42bc20de5..dd91089fcad 100644 --- a/docs/reference/migration/migrate_5_0/search.asciidoc +++ b/docs/reference/migration/migrate_5_0/search.asciidoc @@ -180,6 +180,9 @@ with inner hits defined inside the query dsl. * Source filtering for inner hits inside nested queries requires full field names instead of relative field names. This is now consistent for source filtering on other places in the search API. +* Nested inner hits will now no longer include `_index`, `_type` and `_id` keys. For nested inner hits these values +are always the same as the `_index`, `_type` and `_id` keys of the root search hit. + ==== Query Profiler In the response for profiling queries, the `query_type` has been renamed to `type` and `lucene` has been renamed to diff --git a/docs/reference/search/request/inner-hits.asciidoc b/docs/reference/search/request/inner-hits.asciidoc index 7fe200292a9..345bc9abde2 100644 --- a/docs/reference/search/request/inner-hits.asciidoc +++ b/docs/reference/search/request/inner-hits.asciidoc @@ -118,8 +118,6 @@ An example of a response snippet that could be generated from the above search r "total": ..., "hits": [ { - "_type": "question", - "_id": "1", "_nested": { "field": "comments", "offset": 2 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yaml new file mode 100644 index 00000000000..66b36b58bb7 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yaml @@ -0,0 +1,84 @@ +--- +setup: + - do: + indices.create: + index: test + body: + mappings: + type_1: { + properties: { + nested_field : { + type: nested + } + } + } + type_2: {} + type_3: { + _parent: { + type: type_2 + } + } + +--- +"Nested inner hits": + - do: + index: + index: test + type: type_1 + id: 1 + body: { + "nested_field" : [ + { + "foo": "bar" + } + ] + } + + - do: + indices.refresh: {} + + - do: + search: + body: { "query" : { "nested" : { "path" : "nested_field", "query" : { "match_all" : {} }, "inner_hits" : {} } } } + - match: { hits.total: 1 } + - match: { hits.hits.0._index: "test" } + - match: { hits.hits.0._type: "type_1" } + - match: { hits.hits.0._id: "1" } + - is_false: hits.hits.0.inner_hits.nested_field.hits.hits.0._index + - is_false: hits.hits.0.inner_hits.nested_field.hits.hits.0._type + - is_false: hits.hits.0.inner_hits.nested_field.hits.hits.0._id + - match: { hits.hits.0.inner_hits.nested_field.hits.hits.0._nested.field: "nested_field" } + - match: { hits.hits.0.inner_hits.nested_field.hits.hits.0._nested.offset: 0 } + - is_false: hits.hits.0.inner_hits.nested_field.hits.hits.0._nested.child + +--- +"Parent/child inner hits": + - do: + index: + index: test + type: type_2 + id: 1 + body: {"foo": "bar"} + + - do: + index: + index: test + type: type_3 + id: 1 + parent: 1 + body: {"bar": "baz"} + + - do: + indices.refresh: {} + + - do: + search: + body: { "query" : { "has_child" : { "type" : "type_3", "query" : { "match_all" : {} }, "inner_hits" : {} } } } + - match: { hits.total: 1 } + - match: { hits.hits.0._index: "test" } + - match: { hits.hits.0._type: "type_2" } + - match: { hits.hits.0._id: "1" } + - match: { hits.hits.0.inner_hits.type_3.hits.hits.0._index: "test" } + - match: { hits.hits.0.inner_hits.type_3.hits.hits.0._type: "type_3" } + - match: { hits.hits.0.inner_hits.type_3.hits.hits.0._id: "1" } + - is_false: hits.hits.0.inner_hits.type_3.hits.hits.0._nested From ba1d6907ab77ed05a38cea7198f65faa84e00c5a Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 20 Jun 2016 18:00:34 -0400 Subject: [PATCH 85/87] Quiet the logging of the docs tests Significantly quiets the logging of the docs tests by: 1. Switching two log statements to debug level. 2. Only calling ESTestCase#afterIfFailed if the test failure wasn't just assumptions being violated. --- .../java/org/elasticsearch/test/ESTestCase.java | 16 ++++++++++++++-- .../elasticsearch/test/rest/ESRestTestCase.java | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 172c99592df..e7e6eca5c88 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -73,6 +73,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; +import org.junit.internal.AssumptionViolatedException; import org.junit.rules.RuleChain; import java.io.IOException; @@ -140,13 +141,24 @@ public abstract class ESTestCase extends LuceneTestCase { @Override protected void afterAlways(List errors) throws Throwable { if (errors != null && errors.isEmpty() == false) { - ESTestCase.this.afterIfFailed(errors); + boolean allAssumption = true; + for (Throwable error : errors) { + if (false == error instanceof AssumptionViolatedException) { + allAssumption = false; + break; + } + } + if (false == allAssumption) { + ESTestCase.this.afterIfFailed(errors); + } } super.afterAlways(errors); } }); - /** called when a test fails, supplying the errors it generated */ + /** + * Called when a test fails, supplying the errors it generated. Not called when the test fails because assumptions are violated. + */ protected void afterIfFailed(List errors) { } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index ab2c1d2afbe..a730e046335 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -386,11 +386,11 @@ public abstract class ESRestTestCase extends ESTestCase { } if (!testCandidate.getSetupSection().isEmpty()) { - logger.info("start setup test [{}]", testCandidate.getTestPath()); + logger.debug("start setup test [{}]", testCandidate.getTestPath()); for (DoSection doSection : testCandidate.getSetupSection().getDoSections()) { doSection.execute(restTestExecutionContext); } - logger.info("end setup test [{}]", testCandidate.getTestPath()); + logger.debug("end setup test [{}]", testCandidate.getTestPath()); } restTestExecutionContext.clear(); From 0160d91c2c4d7a0df52e6ed2212d9d0bac6c5375 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Tue, 21 Jun 2016 15:18:59 +0200 Subject: [PATCH 86/87] Removed docs for precision_step - no longer used --- docs/reference/mapping/params.asciidoc | 2 - .../mapping/params/precision-step.asciidoc | 56 ------------------- .../mapping/types/geo-point.asciidoc | 6 -- .../mapping/types/token-count.asciidoc | 5 -- 4 files changed, 69 deletions(-) delete mode 100644 docs/reference/mapping/params/precision-step.asciidoc diff --git a/docs/reference/mapping/params.asciidoc b/docs/reference/mapping/params.asciidoc index d0591a7479f..5134ab6733a 100644 --- a/docs/reference/mapping/params.asciidoc +++ b/docs/reference/mapping/params.asciidoc @@ -80,8 +80,6 @@ include::params/null-value.asciidoc[] include::params/position-increment-gap.asciidoc[] -include::params/precision-step.asciidoc[] - include::params/properties.asciidoc[] include::params/search-analyzer.asciidoc[] diff --git a/docs/reference/mapping/params/precision-step.asciidoc b/docs/reference/mapping/params/precision-step.asciidoc deleted file mode 100644 index a7ea4d342e7..00000000000 --- a/docs/reference/mapping/params/precision-step.asciidoc +++ /dev/null @@ -1,56 +0,0 @@ -[[precision-step]] -=== `precision_step` - -Most <> datatypes index extra terms representing numeric -ranges for each number to make <> -faster. For instance, this `range` query: - -[source,js] --------------------------------------------------- - "range": { - "number": { - "gte": 0 - "lte": 321 - } - } --------------------------------------------------- - -might be executed internally as a <> that -looks something like this: - -[source,js] --------------------------------------------------- - "terms": { - "number": [ - "0-255", - "256-319" - "320", - "321" - ] - } --------------------------------------------------- - -These extra terms greatly reduce the number of terms that have to be examined, -at the cost of increased disk space. - -The default value for `precision_step` depends on the `type` of the numeric field: - -[horizontal] -`long`, `double`, `date`, `ip`:: `16` (3 extra terms) -`integer`, `float`, `short`:: `8` (3 extra terms) -`byte`:: `2147483647` (0 extra terms) -`token_count`:: `32` (0 extra terms) - -The value of the `precision_step` setting indicates the number of bits that -should be compressed into an extra term. A `long` value consists of 64 bits, -so a `precision_step` of 16 results in the following terms: - -[horizontal] -Bits 0-15:: `value & 1111111111111111 0000000000000000 0000000000000000 0000000000000000` -Bits 0-31:: `value & 1111111111111111 1111111111111111 0000000000000000 0000000000000000` -Bits 0-47:: `value & 1111111111111111 1111111111111111 1111111111111111 0000000000000000` -Bits 0-63:: `value` - - - - diff --git a/docs/reference/mapping/types/geo-point.asciidoc b/docs/reference/mapping/types/geo-point.asciidoc index 909d9444527..cf2ae13a99c 100644 --- a/docs/reference/mapping/types/geo-point.asciidoc +++ b/docs/reference/mapping/types/geo-point.asciidoc @@ -126,12 +126,6 @@ The following parameters are accepted by `geo_point` fields: Should the geo-point also be indexed as `.lat` and `.lon` sub-fields? Accepts `true` and `false` (default). -<>:: - - Controls the number of extra terms that are indexed for each lat/lon point. - Defaults to `16`. Ignored if `lat_lon` is `false`. - - ==== Using geo-points in scripts When accessing the value of a geo-point in a script, the value is returned as diff --git a/docs/reference/mapping/types/token-count.asciidoc b/docs/reference/mapping/types/token-count.asciidoc index c472c7c7770..49e4e3b424f 100644 --- a/docs/reference/mapping/types/token-count.asciidoc +++ b/docs/reference/mapping/types/token-count.asciidoc @@ -96,11 +96,6 @@ The following parameters are accepted by `token_count` fields: substituted for any explicit `null` values. Defaults to `null`, which means the field is treated as missing. -<>:: - - Controls the number of extra terms that are indexed to make - <> faster. Defaults to `32`. - <>:: Whether the field value should be stored and retrievable separately from From 881afcba6020e115e64a9bce2de0840912975bba Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Tue, 21 Jun 2016 15:42:42 +0200 Subject: [PATCH 87/87] Fixed tests that failed now that BM25 is the default similarity. --- .../functionscore/DecayFunctionScoreIT.java | 15 +++++++++--- .../functionscore/ExplainableScriptIT.java | 2 +- .../search/nested/SimpleNestedIT.java | 4 ++-- .../search/query/MultiMatchQueryIT.java | 4 ++-- .../search/query/SearchQueryIT.java | 24 +++++++++---------- docs/plugins/mapper-attachments.asciidoc | 4 ++-- .../pattern-replace-charfilter.asciidoc | 4 ++-- .../tokenizers/edgengram-tokenizer.asciidoc | 4 ++-- docs/reference/search/uri-request.asciidoc | 4 ++-- .../test/percolate/16_existing_doc.yaml | 2 +- 10 files changed, 38 insertions(+), 29 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java index e17f7bb3efd..1418f476e00 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java @@ -254,10 +254,19 @@ public class DecayFunctionScoreIT extends ESIntegTestCase { } public void testBoostModeSettingWorks() throws Exception { - assertAcked(prepareCreate("test").addMapping( + Settings settings = Settings.builder().put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).build(); + assertAcked(prepareCreate("test").setSettings(settings) + .addMapping( "type1", - jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text") - .endObject().startObject("loc").field("type", "geo_point").endObject().endObject().endObject().endObject())); + jsonBuilder() + .startObject() + .startObject("type1") + .startObject("properties") + .startObject("test").field("type", "text").endObject() + .startObject("loc").field("type", "geo_point").endObject() + .endObject() + .endObject() + .endObject())); ensureYellow(); List indexBuilders = new ArrayList<>(); diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java index eabae8be055..4e929017ebf 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java @@ -86,7 +86,7 @@ public class ExplainableScriptIT extends ESIntegTestCase { assertThat(hit.getId(), equalTo(Integer.toString(idCounter))); assertThat(hit.explanation().toString(), containsString(Double.toString(idCounter) + " = This script returned " + Double.toString(idCounter))); - assertThat(hit.explanation().toString(), containsString("1.0 = tf(freq=1.0), with freq of")); + assertThat(hit.explanation().toString(), containsString("freq=1.0 = termFreq=1.0")); assertThat(hit.explanation().getDetails().length, equalTo(2)); idCounter--; } diff --git a/core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java b/core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java index e0aec941487..07865d6c2b4 100644 --- a/core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java +++ b/core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java @@ -317,8 +317,8 @@ public class SimpleNestedIT extends ESIntegTestCase { assertNoFailures(searchResponse); assertThat(searchResponse.getHits().totalHits(), equalTo(1L)); Explanation explanation = searchResponse.getHits().hits()[0].explanation(); - assertThat(explanation.getValue(), equalTo(2f)); - assertThat(explanation.toString(), startsWith("2.0 = sum of:\n 2.0 = Score based on 2 child docs in range from 0 to 1")); + assertThat(explanation.getValue(), equalTo(searchResponse.getHits().getHits()[0].score())); + assertThat(explanation.toString(), startsWith("0.36464313 = sum of:\n 0.36464313 = Score based on 2 child docs in range from 0 to 1")); } public void testSimpleNestedSorting() throws Exception { diff --git a/core/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java b/core/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java index 33ef2b97216..875256a0f92 100644 --- a/core/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java @@ -439,8 +439,8 @@ public class MultiMatchQueryIT extends ESIntegTestCase { .setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category") .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS) .operator(Operator.OR))).get(); - assertFirstHit(searchResponse, hasId("theone")); - assertSecondHit(searchResponse, hasId("theother")); + assertFirstHit(searchResponse, hasId("theother")); + assertSecondHit(searchResponse, hasId("theone")); assertThat(searchResponse.getHits().hits()[0].getScore(), greaterThan(searchResponse.getHits().hits()[1].getScore())); searchResponse = client().prepareSearch("test") diff --git a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index 5e4a7d6f77f..8cb21dadb9b 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -283,8 +283,8 @@ public class SearchQueryIT extends ESIntegTestCase { searchResponse = client().prepareSearch("test").setQuery( boolQuery().must(matchAllQuery()).must(constantScoreQuery(matchAllQuery()))).get(); assertHitCount(searchResponse, 2L); - assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(Math.sqrt(2), 0.1)); - assertThat((double)searchResponse.getHits().getAt(1).score(),closeTo(Math.sqrt(2), 0.1)); + assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(2.0, 0.1)); + assertThat((double)searchResponse.getHits().getAt(1).score(),closeTo(2.0, 0.1)); } } @@ -336,8 +336,8 @@ public class SearchQueryIT extends ESIntegTestCase { searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("3")).get(); assertHitCount(searchResponse, 2L); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); + assertFirstHit(searchResponse, hasId("2")); + assertSecondHit(searchResponse, hasId("1")); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("4")).get(); assertHitCount(searchResponse, 1L); @@ -377,9 +377,9 @@ public class SearchQueryIT extends ESIntegTestCase { // try the same with multi match query searchResponse = client().prepareSearch().setQuery(multiMatchQuery("the quick brown", "field1", "field2").cutoffFrequency(3).operator(Operator.AND)).get(); assertHitCount(searchResponse, 3L); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); - assertThirdHit(searchResponse, hasId("3")); + assertFirstHit(searchResponse, hasId("3")); + assertSecondHit(searchResponse, hasId("1")); + assertThirdHit(searchResponse, hasId("2")); } public void testCommonTermsQueryStackedTokens() throws Exception { @@ -423,8 +423,8 @@ public class SearchQueryIT extends ESIntegTestCase { searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("5")).get(); assertHitCount(searchResponse, 2L); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); + assertFirstHit(searchResponse, hasId("2")); + assertSecondHit(searchResponse, hasId("1")); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("6")).get(); assertHitCount(searchResponse, 1L); @@ -469,9 +469,9 @@ public class SearchQueryIT extends ESIntegTestCase { // try the same with multi match query searchResponse = client().prepareSearch().setQuery(multiMatchQuery("the fast brown", "field1", "field2").cutoffFrequency(3).operator(Operator.AND)).get(); assertHitCount(searchResponse, 3L); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); - assertThirdHit(searchResponse, hasId("3")); + assertFirstHit(searchResponse, hasId("3")); + assertSecondHit(searchResponse, hasId("1")); + assertThirdHit(searchResponse, hasId("2")); } public void testQueryStringAnalyzedWildcard() throws Exception { diff --git a/docs/plugins/mapper-attachments.asciidoc b/docs/plugins/mapper-attachments.asciidoc index 86e80cb1a26..b287decd4cf 100644 --- a/docs/plugins/mapper-attachments.asciidoc +++ b/docs/plugins/mapper-attachments.asciidoc @@ -88,10 +88,10 @@ If you get a hit for your indexed document, the plugin should be installed and w "took": 53, "hits": { "total": 1, - "max_score": 0.3125, + "max_score": 0.25811607, "hits": [ { - "_score": 0.3125, + "_score": 0.25811607, "_index": "trying-out-mapper-attachments", "_type": "person", "_id": "1", diff --git a/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc b/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc index 24cd203ae26..9299eb800b5 100644 --- a/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc +++ b/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc @@ -230,13 +230,13 @@ The output from the above is: }, "hits": { "total": 1, - "max_score": 0.4375, + "max_score": 0.2824934, "hits": [ { "_index": "my_index", "_type": "my_doc", "_id": "1", - "_score": 0.4375, + "_score": 0.2824934, "_source": { "text": "The fooBarBaz method" }, diff --git a/docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc b/docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc index 2328354998e..0728767896a 100644 --- a/docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc +++ b/docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc @@ -302,13 +302,13 @@ GET my_index/_search }, "hits": { "total": 1, - "max_score": 0.44194174, + "max_score": 0.51623213, "hits": [ { "_index": "my_index", "_type": "doc", "_id": "1", - "_score": 0.44194174, + "_score": 0.51623213, "_source": { "title": "Quick Foxes" } diff --git a/docs/reference/search/uri-request.asciidoc b/docs/reference/search/uri-request.asciidoc index 9aa9c17727e..496f04ea4af 100644 --- a/docs/reference/search/uri-request.asciidoc +++ b/docs/reference/search/uri-request.asciidoc @@ -27,13 +27,13 @@ And here is a sample response: }, "hits":{ "total" : 1, - "max_score": 1.0, + "max_score": 0.2876821, "hits" : [ { "_index" : "twitter", "_type" : "tweet", "_id" : "0", - "_score": 1.0, + "_score": 0.2876821, "_source" : { "user" : "kimchy", "date" : "2009-11-15T14:12:12", diff --git a/modules/percolator/src/test/resources/rest-api-spec/test/percolate/16_existing_doc.yaml b/modules/percolator/src/test/resources/rest-api-spec/test/percolate/16_existing_doc.yaml index 9da8b33b996..2d15e2cd222 100644 --- a/modules/percolator/src/test/resources/rest-api-spec/test/percolate/16_existing_doc.yaml +++ b/modules/percolator/src/test/resources/rest-api-spec/test/percolate/16_existing_doc.yaml @@ -114,5 +114,5 @@ term: tag: tag1 - - match: {'matches': [{_index: percolator_index, _id: test_percolator, _score: 1.0}]} + - match: {'matches': [{_index: percolator_index, _id: test_percolator, _score: 0.2876821}]}