Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASSSIDECAR-211 Config APIs for storing CDC/Kafka configs for CDC feature #193

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public final class ApiEndpointsV1
public static final String LIST_CDC_SEGMENTS_ROUTE = API_V1 + CDC_PATH + "/segments";
public static final String STREAM_CDC_SEGMENTS_ROUTE = LIST_CDC_SEGMENTS_ROUTE + "/" + SEGMENT_PATH_PARAM;

public static final String SERVICES_PATH = "/services";
public static final String SERVICE_PARAM = ":service";
public static final String CONFIG = "/config";
public static final String SERVICE_CONFIG_ROUTE = API_V1 + SERVICES_PATH + SERVICE_PARAM + CONFIG;
public static final String GET_SERVICES_CONFIG_ROUTE = API_V1 + SERVICES_PATH;
Comment on lines +127 to +128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the URI should be the same for the service, with different verbs to specify the action:

/api/v1/config/services/:service

  • GET : retrieve configuration for :service
  • DELETE: remove configuration for :service
  • PUT: update configuration for :service

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get verb gets config for all the services, I think it is valuable. If we want to be able to get configs of a given service we can add GET verb on /api/v1/config/services/:service.



public static final String CONNECTED_CLIENT_STATS_ROUTE = API_V1 + CASSANDRA + "/stats/connected-clients";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.cassandra.sidecar.common.request;

import io.netty.handler.codec.http.HttpMethod;
import org.apache.cassandra.sidecar.common.request.data.GetServicesConfigPayload;

/**
* Represents a request for getting configurations for services from "configs" table inside
* sidecar internal keyspace.
*/
public class GetServiceConfigRequest extends JsonRequest<GetServicesConfigPayload>
{
/**
* Constructs a Sidecar request with the given {@code requestURI}. Defaults to {@code ssl} enabled.
*/
public GetServiceConfigRequest()
{
super("/api/v1/services");
}

@Override
public HttpMethod method()
{
return HttpMethod.GET;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.cassandra.sidecar.common.request;

import io.netty.handler.codec.http.HttpMethod;
import org.apache.cassandra.sidecar.common.request.data.PutCdcServiceConfigPayload;

/**
* Request class for updating the config of a given service.
* Ex: updating kafka configs or updating cdc configs
*/
public class PutServiceConfigRequest extends JsonRequest<PutCdcServiceConfigPayload>
{
final PutCdcServiceConfigPayload payload;

public PutServiceConfigRequest(ServiceConfig serviceConfig, PutCdcServiceConfigPayload payload)
{
super(String.format("/api/v1/services/%s/config", serviceConfig.getServiceConfig()));
this.payload = payload;
}

@Override
public Object requestBody()
{
return this.payload;
}

@Override
public HttpMethod method()
{
return HttpMethod.PUT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.cassandra.sidecar.common.request;

/**
* "configs" table inside internal sidecar keyspace stores configs for Kafka and CDC. ServiceConfig identifies
* the service of the configs.
*/
public enum ServiceConfig
{
CDC("cdc"),
KAFKA("kafka");

private final String serviceConfig;

ServiceConfig(String serviceConfig)
{
this.serviceConfig = serviceConfig;
}

public String getServiceConfig()
{
return serviceConfig;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.cassandra.sidecar.common.request.data;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* A class representing a response for the GetServicesConfig api "/api/v1/services" which contains
* configs for all the services in the "configs" table.
*/
public class GetServicesConfigPayload
{
public final List<Service> services;

@JsonCreator
public GetServicesConfigPayload(@JsonProperty("services") List<Service> services)
{
this.services = services;
}

@JsonProperty("services")
public List<Service> services()
{
return services;
}

@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GetServicesConfigPayload that = (GetServicesConfigPayload) o;
return Objects.equals(services, that.services);
}

@Override
public int hashCode()
{
return Objects.hash(services);
}

/**
* POJO class that represent config for a given service in "configs" table in sidecar
* internal keyspace
*/
public static class Service
{
public final String service;
public final Map<String, String> config;

@JsonCreator
public Service(@JsonProperty("service") String service,
@JsonProperty("config") Map<String, String> config)
{
this.service = service;
this.config = config;
}

@JsonProperty("service")
public String service()
{
return service;
}

@JsonProperty("config")
public Map<String, String> config()
{
return config;
}

@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Service service1 = (Service) o;
return Objects.equals(service, service1.service) && Objects.equals(config, service1.config);
}

@Override
public int hashCode()
{
return Objects.hash(service, config);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.cassandra.sidecar.common.request.data;

import java.util.Map;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* A class representing a response for the {@link PutCdcServiceConfigPayload}.
*/
public class PutCdcServiceConfigPayload
{
public final Map<String, String> config;

@JsonCreator
public PutCdcServiceConfigPayload(@JsonProperty("config") Map<String, String> config)
{
this.config = config;
}

@JsonProperty("config")
public Map<String, String> config()
{
return config;
}

@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PutCdcServiceConfigPayload that = (PutCdcServiceConfigPayload) o;
return Objects.equals(config, that.config);
}

@Override
public int hashCode()
{
return Objects.hash(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.cassandra.sidecar.client;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand All @@ -38,16 +39,21 @@
import org.apache.cassandra.sidecar.common.request.AbortRestoreJobRequest;
import org.apache.cassandra.sidecar.common.request.CreateRestoreJobRequest;
import org.apache.cassandra.sidecar.common.request.CreateRestoreJobSliceRequest;
import org.apache.cassandra.sidecar.common.request.GetServiceConfigRequest;
import org.apache.cassandra.sidecar.common.request.ImportSSTableRequest;
import org.apache.cassandra.sidecar.common.request.ListCdcSegmentsRequest;
import org.apache.cassandra.sidecar.common.request.PutServiceConfigRequest;
import org.apache.cassandra.sidecar.common.request.RestoreJobProgressRequest;
import org.apache.cassandra.sidecar.common.request.RestoreJobSummaryRequest;
import org.apache.cassandra.sidecar.common.request.ServiceConfig;
import org.apache.cassandra.sidecar.common.request.StreamCdcSegmentRequest;
import org.apache.cassandra.sidecar.common.request.UpdateRestoreJobRequest;
import org.apache.cassandra.sidecar.common.request.data.AbortRestoreJobRequestPayload;
import org.apache.cassandra.sidecar.common.request.data.CreateRestoreJobRequestPayload;
import org.apache.cassandra.sidecar.common.request.data.CreateSliceRequestPayload;
import org.apache.cassandra.sidecar.common.request.data.Digest;
import org.apache.cassandra.sidecar.common.request.data.GetServicesConfigPayload;
import org.apache.cassandra.sidecar.common.request.data.PutCdcServiceConfigPayload;
import org.apache.cassandra.sidecar.common.request.data.RestoreJobProgressRequestParams;
import org.apache.cassandra.sidecar.common.request.data.UpdateRestoreJobRequestPayload;
import org.apache.cassandra.sidecar.common.response.ConnectedClientStatsResponse;
Expand Down Expand Up @@ -544,6 +550,33 @@ public void streamCdcSegments(SidecarInstance sidecarInstance,
.build(), streamConsumer);
}

/**
* Get configs for all the services in the "configs" table inside sidecar's internal
* keyspace
*
* @return List of services and their corresponding configs
*/
public CompletableFuture<GetServicesConfigPayload> getServiceConfig()
{
return executor.executeRequestAsync(requestBuilder()
.request(new GetServiceConfigRequest())
.build());
}

/**
* Update config for a given service in "configs" table in internal sidecar keyspace
*
* @param serviceConfig service for which the configs are being updated
* @param config the updated config
* @return updated config
*/
public CompletableFuture<PutCdcServiceConfigPayload> putCdcServiceConfig(ServiceConfig serviceConfig, Map<String, String> config)
{
return executor.executeRequestAsync(requestBuilder()
.request(new PutServiceConfigRequest(serviceConfig, new PutCdcServiceConfigPayload(config)))
.build());
}

/**
* {@inheritDoc}
*/
Expand Down
Loading