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 java.util.concurrent.ExecutionException;
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.mdsal.binding.api.WriteTransaction;
23 import org.opendaylight.mdsal.common.api.CommitInfo;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev181019.CurrentPmList;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev181019.CurrentPmListBuilder;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import com.google.common.util.concurrent.FluentFuture;
32 import com.google.common.util.concurrent.Futures;
33 import com.google.inject.Inject;
34 import com.google.inject.name.Named;
36 import io.fd.honeycomb.translate.read.ReaderFactory;
37 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
38 import io.fd.honeycomb.translate.util.read.BindingBrokerReader;
39 import io.fd.honeycomb.transportpce.device.configuration.PmConfiguration;
42 * @author Martial COULIBALY ( mcoulibaly.ext@orange.com ) on behalf of Orange
44 public class PmReaderFactory implements ReaderFactory {
46 private static final Logger LOG = LoggerFactory.getLogger(PmReaderFactory.class);
47 public static final InstanceIdentifier<CurrentPmList> PM_CONTAINER_ID =
48 InstanceIdentifier.create(CurrentPmList.class);
51 @Named("device-databroker")
52 private DataBroker dataBroker;
55 private PmConfiguration pmConfiguration;
59 public void init(final ModifiableReaderRegistryBuilder registry) {
60 registry.add(new BindingBrokerReader<>(PM_CONTAINER_ID, dataBroker,LogicalDatastoreType.OPERATIONAL,
61 CurrentPmListBuilder.class));
66 * Write xml data from {@link PmConfiguration}
67 * to operational data.
70 public boolean writeXMLDataToOper() {
72 LOG.info("writting xml pm file data to oper datastore");
73 CurrentPmList pmList = this.pmConfiguration.getDataPm();
74 if (pmList !=null && pmList.getCurrentPmEntry().size() > 0) {
75 LOG.info("Getting pm info from xml file for device ");
76 CurrentPmListBuilder result = new CurrentPmListBuilder(pmList);
77 InstanceIdentifier<CurrentPmList> iid = InstanceIdentifier.create(CurrentPmList.class);
78 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
79 if (writeTx != null ) {
80 LOG.info("WriteTransaction is ok, copy currentPmList to oper datastore");
81 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, result.build());
82 FluentFuture< ? extends @NonNull CommitInfo> future = writeTx.commit();
84 Futures.getChecked(future, ExecutionException.class);
85 LOG.info("currentPmList writed to oper datastore");
87 } catch (ExecutionException e) {
88 LOG.error("Failed to write currentPmList to oper datastore");
91 LOG.error("WriteTransaction object is null");
94 LOG.error("currentPmList data operation gets from xml file is null !");