2 * Copyright (c) 2018 Orange and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package io.fd.honeycomb.transportpce.device.read;
18 import com.google.common.util.concurrent.Futures;
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
22 import io.fd.honeycomb.translate.read.ReaderFactory;
23 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
24 import io.fd.honeycomb.translate.util.read.BindingBrokerReader;
25 import io.fd.honeycomb.transportpce.device.configuration.PmConfiguration;
27 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.Future;
30 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
31 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
32 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlist;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlistBuilder;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * @author Martial COULIBALY ( mcoulibaly.ext@orange.com ) on behalf of Orange
42 public class PmReaderFactory implements ReaderFactory {
44 private static final Logger LOG = LoggerFactory.getLogger(PmReaderFactory.class);
45 public static final InstanceIdentifier<CurrentPmlist> PM_CONTAINER_ID =
46 InstanceIdentifier.create(CurrentPmlist.class);
49 @Named("device-databroker")
50 private DataBroker dataBroker;
53 private PmConfiguration pmConfiguration;
57 public void init(final ModifiableReaderRegistryBuilder registry) {
58 registry.add(new BindingBrokerReader<>(PM_CONTAINER_ID, dataBroker,LogicalDatastoreType.OPERATIONAL,
59 CurrentPmlistBuilder.class));
64 * Write xml data from {@link PmConfiguration}
65 * to operational data.
68 public boolean writeXMLDataToOper() {
70 LOG.info("writting xml pm file data to oper datastore");
71 CurrentPmlist pmList = this.pmConfiguration.getDataPm();
72 if (pmList !=null && pmList.getCurrentPm().size() > 0) {
73 LOG.info("Getting pm info from xml file for device ");
74 CurrentPmlistBuilder result = new CurrentPmlistBuilder(pmList);
75 InstanceIdentifier<CurrentPmlist> iid = InstanceIdentifier.create(CurrentPmlist.class);
76 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
77 if (writeTx != null ) {
78 LOG.info("WriteTransaction is ok, copy currentPmList to oper datastore");
79 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, result.build());
80 Future<Void> future = writeTx.submit();
82 Futures.getChecked(future, ExecutionException.class);
83 LOG.info("currentPmList writed to oper datastore");
85 } catch (ExecutionException e) {
86 LOG.error("Failed to write currentPmList to oper datastore");
89 LOG.error("WriteTransaction object is null");
92 LOG.error("currentPmList data operation gets from xml file is null !");