Madan Jampani | 0cb0067 | 2015-02-27 00:27:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.store.consistent.impl; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.Set; |
| 20 | |
| 21 | import org.onosproject.store.cluster.impl.NodeInfo; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
| 25 | import com.google.common.collect.ImmutableMap; |
| 26 | import com.google.common.collect.ImmutableSet; |
| 27 | |
| 28 | /** |
| 29 | * Partitioned database configuration. |
| 30 | */ |
| 31 | public class DatabaseDefinition { |
| 32 | private Map<String, Set<NodeInfo>> partitions; |
| 33 | private Set<NodeInfo> nodes; |
| 34 | |
| 35 | /** |
| 36 | * Creates a new DatabaseDefinition. |
| 37 | * @param partitions partition map |
| 38 | * @param nodes set of nodes |
| 39 | * @return database definition |
| 40 | */ |
| 41 | public static DatabaseDefinition from(Map<String, Set<NodeInfo>> partitions, Set<NodeInfo> nodes) { |
| 42 | checkNotNull(partitions); |
| 43 | checkNotNull(nodes); |
| 44 | DatabaseDefinition definition = new DatabaseDefinition(); |
| 45 | definition.partitions = ImmutableMap.copyOf(partitions); |
| 46 | definition.nodes = ImmutableSet.copyOf(nodes); |
| 47 | return definition; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the map of database partitions. |
| 52 | * @return db partition map |
| 53 | */ |
| 54 | public Map<String, Set<NodeInfo>> getPartitions() { |
| 55 | return partitions; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the set of nodes. |
| 60 | * @return nodes |
| 61 | */ |
| 62 | public Set<NodeInfo> getNodes() { |
| 63 | return nodes; |
| 64 | } |
| 65 | } |