All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.instaclustr.cassandra.sidecar.resource.VersionResource Maven / Gradle / Ivy

package com.instaclustr.cassandra.sidecar.resource;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import com.instaclustr.cassandra.CassandraVersion;
import com.instaclustr.cassandra.sidecar.service.CassandraService;
import com.instaclustr.cassandra.sidecar.service.CassandraService.CassandraSchemaVersion;
import com.instaclustr.version.Version;

@Path("/version")
@Produces(APPLICATION_JSON)
public class VersionResource {

    private final Version version;
    private final Provider cassandraVersion;
    private final CassandraService cassandraService;

    @Inject
    public VersionResource(final Version version,
                           final Provider cassandraVersion,
                           final CassandraService cassandraService) {
        this.version = version;
        this.cassandraVersion = cassandraVersion;
        this.cassandraService = cassandraService;
    }

    @GET
    public Response getVersion() {
        return getSidecarVersion();
    }

    @GET
    @Path("sidecar")
    public Response getSidecarVersion() {
        return Response.ok(version).build();
    }

    @GET
    @Path("cassandra")
    public Response getCassandraVersion() {
        return Response.ok(cassandraVersion.get()).build();
    }

    @GET
    @Path("schema")
    public Response getCassandraSchemaVersion() {
        final CassandraSchemaVersion schemaVersion = cassandraService.getCassandraSchemaVersion();

        if (schemaVersion.getException() != null) {
            return Response.serverError().entity(schemaVersion.getException()).build();
        }

        return Response.ok(schemaVersion).build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy