hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.odtn.utils.tapi; |
| 18 | |
| 19 | import java.util.Collections; |
| 20 | import java.util.List; |
| 21 | import java.util.stream.Collectors; |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 22 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.DefaultContext; |
| 23 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.Uuid; |
| 24 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.DefaultConnectivityService; |
| 25 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.context.DefaultAugmentedTapiCommonContext; |
Ai Hamano | 82fdd83 | 2018-11-29 15:44:46 +0900 | [diff] [blame] | 26 | import org.onosproject.yang.gen.v1.tapitopology.rev20181016.tapitopology.context.augmentedtapicommoncontext.DefaultTopologyContext; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 27 | import org.onosproject.yang.model.DefaultModelObjectData; |
| 28 | import org.onosproject.yang.model.ModelObjectData; |
| 29 | import org.onosproject.yang.model.ModelObjectId; |
| 30 | |
| 31 | /** |
| 32 | * Utility class to deal with TAPI Context with DCS. |
| 33 | */ |
| 34 | public final class TapiContextHandler extends TapiObjectHandler<DefaultContext> { |
| 35 | |
| 36 | private TapiContextHandler() { |
| 37 | obj = new DefaultContext(); |
| 38 | } |
| 39 | |
| 40 | public static TapiContextHandler create() { |
| 41 | return new TapiContextHandler(); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | protected Uuid getIdDetail() { |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 46 | // The target yang object of this class is container, so no need to handle Id. |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 47 | return null; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | protected void setIdDetail(Uuid uuid) { |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 52 | // The target yang object of this class is container, so no need to handle Id. |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public ModelObjectId getParentModelObjectId() { |
| 57 | return ModelObjectId.builder().build(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public ModelObjectData getChildModelObjectData() { |
| 62 | |
| 63 | ModelObjectId mId = ModelObjectId.builder() |
| 64 | .addChild(DefaultContext.class) |
| 65 | .build(); |
| 66 | |
Ai Hamano | 82fdd83 | 2018-11-29 15:44:46 +0900 | [diff] [blame] | 67 | DefaultTopologyContext mObj = new DefaultTopologyContext(); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 68 | |
| 69 | return DefaultModelObjectData.builder() |
| 70 | .addModelObject(mObj) |
| 71 | .identifier(mId) |
| 72 | .build(); |
| 73 | } |
| 74 | |
| 75 | public List<TapiConnectivityServiceHandler> getConnectivityServices() { |
| 76 | |
| 77 | DefaultAugmentedTapiCommonContext augmentedContext = obj.augmentation(DefaultAugmentedTapiCommonContext.class); |
| 78 | try { |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 79 | return augmentedContext.connectivityContext().connectivityService().stream() |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 80 | .map(connectivityService -> { |
| 81 | TapiConnectivityServiceHandler handler = TapiConnectivityServiceHandler.create(); |
| 82 | handler.setModelObject((DefaultConnectivityService) connectivityService); |
| 83 | return handler; |
| 84 | }).collect(Collectors.toList()); |
| 85 | } catch (NullPointerException e) { |
| 86 | return Collections.emptyList(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | } |