arjunashok commented on code in PR #139: URL: https://github.com/apache/cassandra-sidecar/pull/139#discussion_r1831788281
########## server/src/main/java/org/apache/cassandra/sidecar/routes/JobStatusHandler.java: ########## @@ -0,0 +1,115 @@ +/* + * 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.UUID; +import javax.inject.Inject; + +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.net.SocketAddress; +import io.vertx.ext.web.RoutingContext; +import org.apache.cassandra.sidecar.common.response.JobStatusResponse; +import org.apache.cassandra.sidecar.concurrent.ExecutorPools; +import org.apache.cassandra.sidecar.job.Job; +import org.apache.cassandra.sidecar.job.JobManager; +import org.apache.cassandra.sidecar.utils.CassandraInputValidator; +import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher; + +import static org.apache.cassandra.sidecar.common.http.SidecarHttpHeaderNames.ASYNC_JOB_UUID; +import static org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException; + +/** + * Handler for retrieving the status of async jobs running on the sidecar + */ +public class JobStatusHandler extends AbstractHandler<Void> +{ + private final JobManager jobManager; + @Inject + public JobStatusHandler(InstanceMetadataFetcher metadataFetcher, ExecutorPools executorPools, CassandraInputValidator validator, JobManager jobManager) + { + super(metadataFetcher, executorPools, validator); + this.jobManager = jobManager; + } + + protected Void extractParamsOrThrow(RoutingContext context) + { + return null; + } + + @Override + public void handleInternal(RoutingContext context, HttpServerRequest httpRequest, String host, SocketAddress remoteAddress, Void request) + { + UUID jobUUID = verifyJobIdPresent(context); + + executorPools.service().executeBlocking(() -> { + Job job = jobManager.getJobIfExists(jobUUID); + if (job == null) + { + String response = String.format("Unknown job with ID:%s. Please retry the operation.", jobUUID); + logger.info(response); + context.fail(wrapHttpException(HttpResponseStatus.NOT_FOUND, response)); + } + return job; + }) + .onFailure(cause -> processFailure(cause, context, host, remoteAddress, request)) + .onSuccess(job -> sendStatusBasedResponse(context, jobUUID, job)); + } + + private UUID verifyJobIdPresent(RoutingContext context) Review Comment: Fair point, will update. -- 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]

