Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [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.xosintegration; |
| 17 | |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | public final class VoltTenant { |
| 21 | |
| 22 | private final String humanReadableName; |
| 23 | private final long id; |
| 24 | private final long providerService; |
| 25 | private final String serviceSpecificId; |
| 26 | private final String vlanId; |
| 27 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Constructs a vOLT tenant object. |
| 30 | * |
| 31 | * @param humanReadableName name string |
| 32 | * @param id identifier for the tenant |
| 33 | * @param providerService provider service ID |
| 34 | * @param serviceSpecificId id for the user |
| 35 | * @param vlanId vlan id for the user |
| 36 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 37 | private VoltTenant(String humanReadableName, long id, long providerService, |
| 38 | String serviceSpecificId, String vlanId) { |
| 39 | this.humanReadableName = humanReadableName; |
| 40 | this.id = id; |
| 41 | this.providerService = providerService; |
| 42 | this.serviceSpecificId = serviceSpecificId; |
| 43 | this.vlanId = vlanId; |
| 44 | } |
| 45 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Fetches a builder to make a tenant. |
| 48 | * |
| 49 | * @return tenant builder |
| 50 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 51 | public static Builder builder() { |
| 52 | return new Builder(); |
| 53 | } |
| 54 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 55 | /** |
| 56 | * Fetches the name of the tenant. |
| 57 | * |
| 58 | * @return human readable name |
| 59 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 60 | public String humanReadableName() { |
| 61 | return humanReadableName; |
| 62 | } |
| 63 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 64 | /** |
| 65 | * Fetches the ID of the tenant object. |
| 66 | * |
| 67 | * @return ID of tenant object. |
| 68 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 69 | public long id() { |
| 70 | return id; |
| 71 | } |
| 72 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 73 | /** |
| 74 | * Fetches the identifier for the provider service. |
| 75 | * |
| 76 | * @return provider service ID |
| 77 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 78 | public long providerService() { |
| 79 | return providerService; |
| 80 | } |
| 81 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 82 | /** |
| 83 | * Fetches the server specific ID (user id). |
| 84 | * |
| 85 | * @return server specific ID |
| 86 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 87 | public String serviceSpecificId() { |
| 88 | return serviceSpecificId; |
| 89 | } |
| 90 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Fetches the vlan id for this tenant. |
| 93 | * |
| 94 | * @return VLAN ID |
| 95 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 96 | public String vlanId() { |
| 97 | return vlanId; |
| 98 | } |
| 99 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Builder class to allow callers to assemble tenants. |
| 102 | */ |
| 103 | |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 104 | public static final class Builder { |
| 105 | private String humanReadableName = "unknown"; |
| 106 | private long id = 0; |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 107 | private long providerService = -1; |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 108 | private String serviceSpecificId = "unknown"; |
| 109 | private String vlanId = "unknown"; |
| 110 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Sets the name string for the tenant. |
| 113 | * |
| 114 | * @param humanReadableName name |
| 115 | * @return self |
| 116 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 117 | public Builder withHumanReadableName(String humanReadableName) { |
| 118 | this.humanReadableName = humanReadableName; |
| 119 | return this; |
| 120 | } |
| 121 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 122 | /** |
| 123 | * Sets the identifier for the tenant. |
| 124 | * |
| 125 | * @param id identifier for the tenant |
| 126 | * @return self |
| 127 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 128 | public Builder withId(long id) { |
| 129 | this.id = id; |
| 130 | return this; |
| 131 | } |
| 132 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 133 | /** |
| 134 | * Sets the server specific id (user id) for the tenant. |
| 135 | * |
| 136 | * @param serviceSpecificId server specific (user) id |
| 137 | * @return self |
| 138 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 139 | public Builder withServiceSpecificId(String serviceSpecificId) { |
| 140 | this.serviceSpecificId = serviceSpecificId; |
| 141 | return this; |
| 142 | } |
| 143 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 144 | /** |
| 145 | * Sets the VLAN ID for the tenant. |
| 146 | * |
| 147 | * @param vlanId VLAN ID |
| 148 | * @return self |
| 149 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 150 | public Builder withVlanId(String vlanId) { |
| 151 | this.vlanId = vlanId; |
| 152 | return this; |
| 153 | } |
| 154 | |
Ray Milkey | dea9817 | 2015-05-18 10:39:39 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Sets the provider service ID. |
| 157 | * |
| 158 | * @param providerService provider service ID |
| 159 | * @return self |
| 160 | */ |
| 161 | public Builder withProviderService(long providerService) { |
| 162 | this.providerService = providerService; |
| 163 | return this; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Constructs a VoltTenant from the assembled data. |
| 168 | * |
| 169 | * @return constructed tenant object |
| 170 | */ |
Ray Milkey | 140e478 | 2015-04-24 11:25:13 -0700 | [diff] [blame] | 171 | public VoltTenant build() { |
| 172 | return new VoltTenant(humanReadableName, id, providerService, |
| 173 | serviceSpecificId, vlanId); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public String toString() { |
| 179 | return MoreObjects.toStringHelper(getClass()) |
| 180 | .add("humanReadableName", humanReadableName()) |
| 181 | .add("id", id()) |
| 182 | .add("providerService", providerService()) |
| 183 | .add("serviceSpecificId", serviceSpecificId()) |
| 184 | .add("vlanId", vlanId()) |
| 185 | .toString(); |
| 186 | } |
| 187 | |
| 188 | } |