
software.amazon.awssdk.services.cloudwatchlogs.model.PutQueryDefinitionRequest Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.services.cloudwatchlogs.model;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class PutQueryDefinitionRequest extends CloudWatchLogsRequest implements
ToCopyableBuilder {
private static final SdkField NAME_FIELD = SdkField. builder(MarshallingType.STRING).memberName("name")
.getter(getter(PutQueryDefinitionRequest::name)).setter(setter(Builder::name))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("name").build()).build();
private static final SdkField QUERY_DEFINITION_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("queryDefinitionId").getter(getter(PutQueryDefinitionRequest::queryDefinitionId))
.setter(setter(Builder::queryDefinitionId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("queryDefinitionId").build()).build();
private static final SdkField> LOG_GROUP_NAMES_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("logGroupNames")
.getter(getter(PutQueryDefinitionRequest::logGroupNames))
.setter(setter(Builder::logGroupNames))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("logGroupNames").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField QUERY_STRING_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("queryString").getter(getter(PutQueryDefinitionRequest::queryString))
.setter(setter(Builder::queryString))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("queryString").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(NAME_FIELD,
QUERY_DEFINITION_ID_FIELD, LOG_GROUP_NAMES_FIELD, QUERY_STRING_FIELD));
private final String name;
private final String queryDefinitionId;
private final List logGroupNames;
private final String queryString;
private PutQueryDefinitionRequest(BuilderImpl builder) {
super(builder);
this.name = builder.name;
this.queryDefinitionId = builder.queryDefinitionId;
this.logGroupNames = builder.logGroupNames;
this.queryString = builder.queryString;
}
/**
*
* A name for the query definition. If you are saving a lot of query definitions, we recommend that you name them so
* that you can easily find the ones you want by using the first part of the name as a filter in the
* queryDefinitionNamePrefix
parameter of DescribeQueryDefinitions.
*
*
* @return A name for the query definition. If you are saving a lot of query definitions, we recommend that you name
* them so that you can easily find the ones you want by using the first part of the name as a filter in the
* queryDefinitionNamePrefix
parameter of DescribeQueryDefinitions.
*/
public final String name() {
return name;
}
/**
*
* If you are updating a query definition, use this parameter to specify the ID of the query definition that you
* want to update. You can use DescribeQueryDefinitions to retrieve the IDs of your saved query definitions.
*
*
* If you are creating a query definition, do not specify this parameter. CloudWatch generates a unique ID for the
* new query definition and include it in the response to this operation.
*
*
* @return If you are updating a query definition, use this parameter to specify the ID of the query definition that
* you want to update. You can use DescribeQueryDefinitions to retrieve the IDs of your saved query definitions.
*
* If you are creating a query definition, do not specify this parameter. CloudWatch generates a unique ID
* for the new query definition and include it in the response to this operation.
*/
public final String queryDefinitionId() {
return queryDefinitionId;
}
/**
* For responses, this returns true if the service returned a value for the LogGroupNames property. This DOES NOT
* check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property).
* This is useful because the SDK will never return a null collection or map, but you may need to differentiate
* between the service returning nothing (or null) and the service returning an empty collection or map. For
* requests, this returns true if a value for the property was specified in the request builder, and false if a
* value was not specified.
*/
public final boolean hasLogGroupNames() {
return logGroupNames != null && !(logGroupNames instanceof SdkAutoConstructList);
}
/**
*
* Use this parameter to include specific log groups as part of your query definition.
*
*
* If you are updating a query definition and you omit this parameter, then the updated definition will contain no
* log groups.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasLogGroupNames} method.
*
*
* @return Use this parameter to include specific log groups as part of your query definition.
*
* If you are updating a query definition and you omit this parameter, then the updated definition will
* contain no log groups.
*/
public final List logGroupNames() {
return logGroupNames;
}
/**
*
* The query string to use for this definition. For more information, see CloudWatch Logs Insights
* Query Syntax.
*
*
* @return The query string to use for this definition. For more information, see CloudWatch Logs
* Insights Query Syntax.
*/
public final String queryString() {
return queryString;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(name());
hashCode = 31 * hashCode + Objects.hashCode(queryDefinitionId());
hashCode = 31 * hashCode + Objects.hashCode(hasLogGroupNames() ? logGroupNames() : null);
hashCode = 31 * hashCode + Objects.hashCode(queryString());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof PutQueryDefinitionRequest)) {
return false;
}
PutQueryDefinitionRequest other = (PutQueryDefinitionRequest) obj;
return Objects.equals(name(), other.name()) && Objects.equals(queryDefinitionId(), other.queryDefinitionId())
&& hasLogGroupNames() == other.hasLogGroupNames() && Objects.equals(logGroupNames(), other.logGroupNames())
&& Objects.equals(queryString(), other.queryString());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("PutQueryDefinitionRequest").add("Name", name()).add("QueryDefinitionId", queryDefinitionId())
.add("LogGroupNames", hasLogGroupNames() ? logGroupNames() : null).add("QueryString", queryString()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "name":
return Optional.ofNullable(clazz.cast(name()));
case "queryDefinitionId":
return Optional.ofNullable(clazz.cast(queryDefinitionId()));
case "logGroupNames":
return Optional.ofNullable(clazz.cast(logGroupNames()));
case "queryString":
return Optional.ofNullable(clazz.cast(queryString()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function
*
* If you are creating a query definition, do not specify this parameter. CloudWatch generates a unique
* ID for the new query definition and include it in the response to this operation.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder queryDefinitionId(String queryDefinitionId);
/**
*
* Use this parameter to include specific log groups as part of your query definition.
*
*
* If you are updating a query definition and you omit this parameter, then the updated definition will contain
* no log groups.
*
*
* @param logGroupNames
* Use this parameter to include specific log groups as part of your query definition.
*
* If you are updating a query definition and you omit this parameter, then the updated definition will
* contain no log groups.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder logGroupNames(Collection logGroupNames);
/**
*
* Use this parameter to include specific log groups as part of your query definition.
*
*
* If you are updating a query definition and you omit this parameter, then the updated definition will contain
* no log groups.
*
*
* @param logGroupNames
* Use this parameter to include specific log groups as part of your query definition.
*
* If you are updating a query definition and you omit this parameter, then the updated definition will
* contain no log groups.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder logGroupNames(String... logGroupNames);
/**
*
* The query string to use for this definition. For more information, see CloudWatch Logs Insights
* Query Syntax.
*
*
* @param queryString
* The query string to use for this definition. For more information, see CloudWatch Logs
* Insights Query Syntax.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder queryString(String queryString);
@Override
Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration);
@Override
Builder overrideConfiguration(Consumer builderConsumer);
}
static final class BuilderImpl extends CloudWatchLogsRequest.BuilderImpl implements Builder {
private String name;
private String queryDefinitionId;
private List logGroupNames = DefaultSdkAutoConstructList.getInstance();
private String queryString;
private BuilderImpl() {
}
private BuilderImpl(PutQueryDefinitionRequest model) {
super(model);
name(model.name);
queryDefinitionId(model.queryDefinitionId);
logGroupNames(model.logGroupNames);
queryString(model.queryString);
}
public final String getName() {
return name;
}
public final void setName(String name) {
this.name = name;
}
@Override
public final Builder name(String name) {
this.name = name;
return this;
}
public final String getQueryDefinitionId() {
return queryDefinitionId;
}
public final void setQueryDefinitionId(String queryDefinitionId) {
this.queryDefinitionId = queryDefinitionId;
}
@Override
public final Builder queryDefinitionId(String queryDefinitionId) {
this.queryDefinitionId = queryDefinitionId;
return this;
}
public final Collection getLogGroupNames() {
if (logGroupNames instanceof SdkAutoConstructList) {
return null;
}
return logGroupNames;
}
public final void setLogGroupNames(Collection logGroupNames) {
this.logGroupNames = LogGroupNamesCopier.copy(logGroupNames);
}
@Override
public final Builder logGroupNames(Collection logGroupNames) {
this.logGroupNames = LogGroupNamesCopier.copy(logGroupNames);
return this;
}
@Override
@SafeVarargs
public final Builder logGroupNames(String... logGroupNames) {
logGroupNames(Arrays.asList(logGroupNames));
return this;
}
public final String getQueryString() {
return queryString;
}
public final void setQueryString(String queryString) {
this.queryString = queryString;
}
@Override
public final Builder queryString(String queryString) {
this.queryString = queryString;
return this;
}
@Override
public Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration) {
super.overrideConfiguration(overrideConfiguration);
return this;
}
@Override
public Builder overrideConfiguration(Consumer builderConsumer) {
super.overrideConfiguration(builderConsumer);
return this;
}
@Override
public PutQueryDefinitionRequest build() {
return new PutQueryDefinitionRequest(this);
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
}
}