Aihua Guo | eb9b378 | 2016-09-09 01:11:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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.tetopology.management.impl; |
| 17 | |
| 18 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.incubator.net.config.basics.ConfigException; |
| 20 | import org.onosproject.net.config.Config; |
| 21 | import org.onosproject.tetopology.management.api.TeTopologyId; |
| 22 | |
| 23 | /** |
| 24 | * Configuration for TE Topology Identifiers. |
| 25 | */ |
| 26 | public class TeTopologyIdConfig extends Config<ApplicationId> { |
| 27 | public static final String CONFIG_VALUE_ERROR = "Error parsing config value"; |
| 28 | private static final String PROVIDER_ID = "provider-id"; |
| 29 | private static final String CLIENT_ID = "client-id"; |
| 30 | private static final String TOPOLOGY_ID = "topology-id"; |
| 31 | |
| 32 | /** |
| 33 | * Generates TE topology identifier. |
| 34 | * |
| 35 | * @return encoded TE topology identifier |
| 36 | * @throws ConfigException if the parameters are not correctly configured |
| 37 | * or conversion of the parameters fails |
| 38 | */ |
| 39 | public TeTopologyId getTeTopologyId() throws ConfigException { |
| 40 | try { |
| 41 | long providerId = object.path(PROVIDER_ID).asLong(); |
| 42 | long clientId = object.path(CLIENT_ID).asLong(); |
| 43 | String topologyId = object.path(TOPOLOGY_ID).asText(); |
| 44 | |
| 45 | return new TeTopologyId(providerId, clientId, topologyId); |
| 46 | |
| 47 | } catch (IllegalArgumentException e) { |
| 48 | throw new ConfigException(CONFIG_VALUE_ERROR, e); |
| 49 | } |
| 50 | } |
| 51 | } |