frankgh commented on code in PR #36: URL: https://github.com/apache/cassandra-sidecar/pull/36#discussion_r961950267
########## src/main/java/org/apache/cassandra/sidecar/routes/KeyspacesHandler.java: ########## @@ -0,0 +1,227 @@ +/* + * 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.routes; + +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.datastax.driver.core.KeyspaceMetadata; +import com.datastax.driver.core.Metadata; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.TableMetadata; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import io.vertx.core.http.HttpMethod; +import io.vertx.core.net.SocketAddress; +import io.vertx.ext.web.RoutingContext; +import io.vertx.ext.web.handler.HttpException; +import org.apache.cassandra.sidecar.cluster.InstancesConfig; +import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata; +import org.apache.cassandra.sidecar.common.data.KeyspaceRequest; +import org.apache.cassandra.sidecar.common.data.KeyspaceSchema; +import org.apache.cassandra.sidecar.common.data.TableSchema; +import org.jetbrains.annotations.NotNull; + +/** + * Handler for getting information about keyspace / tables from a specific Cassandra instance + */ +@Singleton +public class KeyspacesHandler extends AbstractHandler +{ + private static final Logger LOGGER = LoggerFactory.getLogger(KeyspacesHandler.class); + private final Vertx vertx; + + @Inject + public KeyspacesHandler(Vertx vertx, InstancesConfig instancesConfig) + { + super(instancesConfig); + this.vertx = vertx; + } + + /** + * Handles {@code GET} and {@code HEAD} requests for Keyspaces. + * For keyspaces requests only {@code GET} is supported, and it will produce a list of keyspaces with table and + * schema information. For keyspace and table requests both {@code GET} and {@code HEAD} requests are supported. + * + * @param context the event to handle + */ + @Override + public void handle(RoutingContext context) + { + KeyspaceRequest requestParams = extractParamsOrThrow(context); + String host = getHost(context); + SocketAddress remoteAddress = context.request().remoteAddress(); + InstanceMetadata instanceMeta = instancesConfig.instanceFromHost(host); + LOGGER.debug("KeyspacesHandler received request: {} from: {}. Instance: {}", + requestParams, remoteAddress, host); + + getMetadata(instanceMeta) + .onFailure(throwable -> + { Review Comment: +1. I'm updating `checkstyle.xml` to avoid linter errors -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

