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

com.weibo.rill.flow.service.storage.dao.DAGFeatureDAO Maven / Gradle / Ivy

/*
 *  Copyright 2021-2023 Weibo, Inc.
 *
 *    Licensed 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 com.weibo.rill.flow.service.storage.dao;

import com.google.common.collect.Lists;
import com.weibo.rill.flow.common.exception.TaskException;
import com.weibo.rill.flow.common.model.BizError;
import com.weibo.rill.flow.olympicene.storage.redis.api.RedisClient;
import com.weibo.rill.flow.service.util.DAGStorageKeysUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
@Slf4j
public class DAGFeatureDAO {
    @Autowired
    @Qualifier("descriptorRedisClient")
    private RedisClient redisClient;

    public boolean createFeature(String businessId, String featureName) {
        if (DAGStorageKeysUtil.nameInvalid(businessId, featureName)) {
            log.info("createFeature params invalid, businessId:{}, serviceName:{}", businessId, featureName);
            throw new TaskException(BizError.ERROR_DATA_FORMAT);
        }
        redisClient.sadd(businessId, DAGStorageKeysUtil.buildFeatureRedisKey(businessId), Lists.newArrayList(featureName));
        return true;
    }

    public boolean remFeature(String businessId, String featureName) {
        if (DAGStorageKeysUtil.nameInvalid(businessId, featureName)) {
            log.info("remFeature params invalid, businessId:{}, featureName:{}", businessId, featureName);
            throw new TaskException(BizError.ERROR_DATA_FORMAT);
        }

        redisClient.srem(businessId, DAGStorageKeysUtil.buildFeatureRedisKey(businessId), Lists.newArrayList(featureName));
        return true;
    }

    public Set getFeature(String businessId) {
        return redisClient.smembers(businessId, DAGStorageKeysUtil.buildFeatureRedisKey(businessId));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy