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

com.dtsx.astra.sdk.streaming.RegionsClient Maven / Gradle / Ivy

There is a newer version: 1.2.9
Show newest version
package com.dtsx.astra.sdk.streaming;

import com.dtsx.astra.sdk.AbstractApiClient;
import com.dtsx.astra.sdk.streaming.domain.StreamingRegion;
import com.dtsx.astra.sdk.utils.ApiLocator;
import com.dtsx.astra.sdk.utils.ApiResponse;
import com.dtsx.astra.sdk.utils.AstraEnvironment;
import com.dtsx.astra.sdk.utils.JsonUtils;
import com.fasterxml.jackson.core.type.TypeReference;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * Group operation on streaming regions
 */
public class RegionsClient extends AbstractApiClient {

    /** Marshalling beans data -> organization -> availableServerlessRegions */
    private static final TypeReference>>>> TYPE_LIST_REGIONS =
            new TypeReference>>>>(){};

    /** json key. */
    private static final String JSON_ORGANIZATION = "organization";

    /** json key. */
    private static final String JSON_SERVERLESS_REGIONS = "availableServerlessRegions";

    /**
     * As immutable object use builder to initiate the object.
     *
     * @param token
     *      authenticated token
     */
    public RegionsClient(String token) {
        this(token, AstraEnvironment.PROD);
    }

    /**
     * As immutable object use builder to initiate the object.
     *
     * @param env
     *      define target environment to be used
     * @param token
     *      authenticated token
     */
    public RegionsClient(String token, AstraEnvironment env) {
        super(token, env);
    }

    /**
     * Get available serverless for Streaming.
     *
     * @return
     *      serverless regions
     */
    public Stream findAllServerless() {
        // Invoke api
        Map>> res = JsonUtils
                .unmarshallType(GET(getApiDevopsEndpointRegionsServerless())
                .getBody(), TYPE_LIST_REGIONS).getData();
        if (null != res &&
                null != res.get(JSON_ORGANIZATION) &&
                null != res.get(JSON_ORGANIZATION).get(JSON_SERVERLESS_REGIONS)) {
            return res.get(JSON_ORGANIZATION).get(JSON_SERVERLESS_REGIONS).stream();
        }
        return Stream.of();
    }

    /**
     * Endpoint to access schema for namespace.
     *
     * @return
     *      endpoint
     */
    public String getApiDevopsEndpointRegionsServerless() {
        return ApiLocator.getApiDevopsEndpoint(environment) + "/streaming" + "/serverless-regions";
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy