2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.mdsal.provider;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import com.google.common.util.concurrent.Futures;
30 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
31 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
32 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
33 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.MdsalStoreService;
35 import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.StoreYangInput;
36 import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.StoreYangOutput;
37 import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.StoreYangOutputBuilder;
38 import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.response.Status;
39 import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.response.StatusBuilder;
40 import org.opendaylight.yangtools.yang.common.RpcResult;
41 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
42 import org.onap.appc.Constants;
43 import org.onap.appc.mdsal.MDSALStore;
44 import org.onap.appc.mdsal.impl.MDSALStoreFactory;
45 import org.onap.appc.mdsal.objects.BundleInfo;
47 import java.text.SimpleDateFormat;
48 import java.util.Date;
49 import java.util.concurrent.ExecutorService;
50 import java.util.concurrent.Executors;
51 import java.util.concurrent.Future;
53 public class MdsalStoreProvider implements MdsalStoreService ,AutoCloseable{
55 protected DataBroker dataBroker;
56 protected RpcProviderRegistry rpcRegistry;
57 protected NotificationProviderService notificationService;
59 protected BindingAwareBroker.RpcRegistration<MdsalStoreService> rpcRegistration;
60 private final EELFLogger log = EELFManager.getInstance().getLogger(MdsalStoreProvider.class);
61 private final ExecutorService executor;
62 private final static String APP_NAME = "MdsalStoreProvider";
64 public MdsalStoreProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService
65 , RpcProviderRegistry rpcRegistry2){
66 log.info("Creating provider for " + APP_NAME);
67 executor = Executors.newFixedThreadPool(1);
68 this.dataBroker = dataBroker2;
69 this.notificationService = notificationProviderService;
71 this.rpcRegistry = rpcRegistry2;
73 if (this.rpcRegistry != null) {
74 rpcRegistration = rpcRegistry.addRpcImplementation(MdsalStoreService.class, this);
76 log.info("Initialization complete for " + APP_NAME);
81 public void close() throws Exception {
82 log.info("Closing provider for " + APP_NAME);
83 if(this.executor != null){
86 if(this.rpcRegistration != null){
87 rpcRegistration.close();
89 log.info("Successfully closed provider for " + APP_NAME);
93 public Future<RpcResult<StoreYangOutput>> storeYang(StoreYangInput input) {
94 Status status =null;String message=null;
96 BundleInfo bundleInfo = new BundleInfo();
97 bundleInfo.setName(input.getModuleName());
98 bundleInfo.setDescription(input.getModuleName());
99 bundleInfo.setLocation(input.getModuleName());
101 MDSALStore store = MDSALStoreFactory.createMDSALStore();
103 Date revision = new SimpleDateFormat(Constants.YANG_REVISION_FORMAT).parse(Constants.YANG_REVISION);
104 if(!store.isModulePresent(input.getModuleName(),revision)){
105 message = "YANG module saved successfully";
106 store.storeYangModule(input.getYang(),bundleInfo);
109 message = "YANG Module already available";
111 store.storeYangModuleOnLeader(input.getYang(),input.getModuleName());
112 status = new StatusBuilder().setCode(200).setMessage(message).build();
116 message = "Error in storeYang of MdsalStoreProvider";
117 log.error(message,e);
118 status = new StatusBuilder().setCode(500).setMessage(message).build();
120 StoreYangOutputBuilder builder = new StoreYangOutputBuilder().setStatus(status);
121 return Futures.immediateFuture(
123 .<StoreYangOutput>status(true)
124 .withResult(builder.build())