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

org.apache.pulsar.broker.resources.ResourceGroupResources Maven / Gradle / Ivy

There is a newer version: 3.0.7.0-SNAPSHOT-a030c50
Show newest version
/**
 * 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.pulsar.broker.resources;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import org.apache.pulsar.common.policies.data.ResourceGroup;
import org.apache.pulsar.metadata.api.MetadataStore;
import org.apache.pulsar.metadata.api.MetadataStoreException;

public class ResourceGroupResources extends BaseResources {

    private static final String BASE_PATH = "/admin/resourcegroups";

    public ResourceGroupResources(MetadataStore store, int operationTimeoutSec) {
        super(store, ResourceGroup.class, operationTimeoutSec);
    }

    public Optional getResourceGroup(String resourceGroupName) throws MetadataStoreException {
        return get(joinPath(BASE_PATH, resourceGroupName));
    }

    public CompletableFuture> getResourceGroupAsync(String resourceGroupName) {
        return getAsync(joinPath(BASE_PATH, resourceGroupName));
    }

    public boolean resourceGroupExists(String resourceGroupName) throws MetadataStoreException {
        return exists(joinPath(BASE_PATH, resourceGroupName));
    }

    public CompletableFuture resourceGroupExistsAsync(String resourceGroupName) {
        return existsAsync(joinPath(BASE_PATH, resourceGroupName));
    }

    public void createResourceGroup(String resourceGroupName, ResourceGroup rg) throws MetadataStoreException {
        create(joinPath(BASE_PATH, resourceGroupName), rg);
    }

    public void deleteResourceGroup(String resourceGroupName) throws MetadataStoreException {
        delete(joinPath(BASE_PATH, resourceGroupName));
    }

    public void updateResourceGroup(String resourceGroupName,
                                    Function modifyFunction)
            throws MetadataStoreException {
        set(joinPath(BASE_PATH, resourceGroupName), modifyFunction);
    }

    public List listResourceGroups() throws MetadataStoreException {
        return getChildren(BASE_PATH);
    }

    public CompletableFuture> listResourceGroupsAsync(){
        return getChildrenAsync(BASE_PATH);
    }

    public static boolean isResourceGroupPath(String path) {
        return path.startsWith(BASE_PATH);
    }

    public static Optional resourceGroupNameFromPath(String path) {
        if (path.length() > BASE_PATH.length() + 1) {
            return Optional.of(path.substring(BASE_PATH.length() + 1));
        } else {
            return Optional.empty();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy