2 * Copyright © 2015 Yale University and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.alto.core.impl.ird.test;
10 import java.util.concurrent.Future;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AddResourceInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AltoResourcepoolService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourcePool;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ServiceContext;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.Resource;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.ResourceId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.ird.rev151021.ResourceTypeIrd;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev151021.AltoModelBaseService;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev151021.QueryInput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev151021.QueryOutput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev151021.QueryOutputBuilder;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 public class AltoIrdProvider implements BindingAwareProvider, AutoCloseable, AltoModelBaseService {
45 private static final Logger LOG = LoggerFactory.getLogger(AltoIrdProvider.class);
47 private DataBroker m_dataBrokerService = null;
48 private RoutedRpcRegistration<AltoModelBaseService> m_serviceReg = null;
49 private AltoResourcepoolService m_resourcepoolService = null;
51 private static final ResourceId TEST_IRD_RID = new ResourceId("test-model-ird");
52 private InstanceIdentifier<Resource> m_testIID = null;
54 protected InstanceIdentifier<Resource> getResourceIID(ResourceId rid) {
55 ResourceKey key = new ResourceKey(rid);
56 return InstanceIdentifier.builder(ResourcePool.class).child(Resource.class, key).build();
60 public void onSessionInitiated(ProviderContext session) {
61 LOG.info("AltoModelIrdProvider Session Initiated");
63 m_dataBrokerService = session.getSALService(DataBroker.class);
64 m_serviceReg = session.addRoutedRpcImplementation(AltoModelBaseService.class, this);
66 ResourceBuilder builder = new ResourceBuilder();
67 builder.setResourceId(TEST_IRD_RID).setType(ResourceTypeIrd.class);
69 AddResourceInputBuilder inputBuilder = new AddResourceInputBuilder();
70 inputBuilder.fieldsFrom(builder.build());
73 AltoResourcepoolService resourcepool;
74 resourcepool = session.getRpcService(AltoResourcepoolService.class);
76 RpcResult<Void> result;
77 result = resourcepool.addResource(inputBuilder.build()).get();
79 assert result.isSuccessful();
81 m_testIID = getResourceIID(TEST_IRD_RID);
82 m_serviceReg.registerPath(ServiceContext.class, m_testIID);
83 } catch (Exception e) {
88 public void close() throws Exception {
89 LOG.info("AltoModelBaseProvider Closed");
93 public Future<RpcResult<QueryOutput>> query(QueryInput input) {
94 if (!input.getType().equals(ResourceTypeIrd.class)) {
95 return RpcResultBuilder.<QueryOutput>failed().buildFuture();
97 QueryOutputBuilder builder = new QueryOutputBuilder();
99 builder.setType(ResourceTypeIrd.class);
100 return RpcResultBuilder.<QueryOutput>success(builder.build()).buildFuture();