001/* 002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * 017 * Contributors: 018 * bdelbosc 019 */ 020package org.nuxeo.runtime.stream; 021 022import java.util.ArrayList; 023import java.util.HashMap; 024import java.util.List; 025import java.util.Map; 026 027import org.nuxeo.common.xmap.annotation.XNode; 028import org.nuxeo.common.xmap.annotation.XNodeList; 029import org.nuxeo.common.xmap.annotation.XNodeMap; 030import org.nuxeo.common.xmap.annotation.XObject; 031 032@SuppressWarnings("CanBeFinal") 033@XObject("logConfig") 034public class LogConfigDescriptor { 035 036 @XNode("@name") 037 public String name; 038 039 @XNode("@type") 040 public String type; 041 042 @XNodeMap(value = "option", key = "@name", type = HashMap.class, componentType = String.class) 043 public Map<String, String> options = new HashMap<>(); 044 045 @XNodeList(value = "log", type = ArrayList.class, componentType = StreamDescriptor.class) 046 public List<StreamDescriptor> logs = new ArrayList<>(0); 047 048 public String getName() { 049 return name; 050 } 051 052 public boolean isKafkaLog() { 053 return "kafka".equalsIgnoreCase(type); 054 } 055 056 public String getOption(String key, String defaultValue) { 057 return options.getOrDefault(key, defaultValue); 058 } 059 060 public Map<String, Integer> getLogsToCreate() { 061 Map<String, Integer> ret = new HashMap<>(); 062 logs.forEach(d -> ret.put(d.name, d.size)); 063 return ret; 064 } 065 066 @XObject(value = "log") 067 public static class StreamDescriptor { 068 public static final Integer DEFAULT_PARTITIONS = 4; 069 070 @XNode("@name") 071 public String name; 072 073 @XNode("@size") 074 public Integer size = DEFAULT_PARTITIONS; 075 076 public StreamDescriptor() { 077 } 078 } 079 080}