/** * Copyright (C) 2014-2016 LinkedIn Corp. (pinot-core@linkedin.com) * * 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.linkedin.pinot.common.config; import com.linkedin.pinot.common.utils.DataSize; import javax.annotation.Nullable; import org.apache.commons.configuration.ConfigurationRuntimeException; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Class representing table quota configuration */ @JsonIgnoreProperties(ignoreUnknown = true) public class QuotaConfig { private static final Logger LOGGER = LoggerFactory.getLogger(QuotaConfig.class); private String storage; static final String STORAGE_FIELD_NAME = "storage"; static final String QUOTA_SECTION_NAME = "quota"; public @Nullable String getStorage() { return storage; } public void setStorage(@Nullable String storage) { this.storage = storage; } /** * Get the storage quota configured value in bytes * @return configured size in bytes or -1 if the value is missing or * unparseable */ public long storageSizeBytes() { return DataSize.toBytes(this.storage); } public JSONObject toJson() { JSONObject quotaObject = new JSONObject(); try { quotaObject.put(STORAGE_FIELD_NAME, storage); } catch (JSONException e) { LOGGER.error("Failed to convert to json", e); } return quotaObject; } public String toString() { return toJson().toString(); } public void validate() { if (storage != null && DataSize.toBytes(storage) < 0) { LOGGER.error("Failed to convert storage quota config: {} to bytes", storage); throw new ConfigurationRuntimeException("Failed to convert storage quota config: " + storage + " to bytes"); } } }