2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowplugin.impl.device.initialization;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.Futures;
13 import java.util.Collections;
14 import java.util.concurrent.Future;
15 import javax.annotation.Nonnull;
16 import javax.annotation.Nullable;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.openflowplugin.api.ConnectionException;
19 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
20 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public abstract class AbstractDeviceInitializer {
28 private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceInitializer.class);
31 * Perform initial information gathering and store them to operational datastore.
33 * @param deviceContext device context
34 * @param switchFeaturesMandatory is switch features mandatory
35 * @param skipTableFeatures skip collecting of table features
36 * @param multipartWriterProvider multipart writer provider
37 * @param convertorExecutor convertor executor
39 @SuppressWarnings("checkstyle:IllegalCatch")
40 public Future<Void> initialize(@Nonnull final DeviceContext deviceContext,
41 final boolean switchFeaturesMandatory,
42 final boolean skipTableFeatures,
43 @Nullable final MultipartWriterProvider multipartWriterProvider,
44 @Nullable final ConvertorExecutor convertorExecutor) {
45 Preconditions.checkNotNull(deviceContext);
47 // Write node to datastore
48 LOG.debug("Initializing node information for node {}", deviceContext.getDeviceInfo());
50 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, deviceContext
52 .getNodeInstanceIdentifier(),
54 .setId(deviceContext.getDeviceInfo().getNodeId())
55 .setNodeConnector(Collections.emptyList())
57 } catch (final Exception e) {
58 LOG.warn("Failed to write node {} to DS ", deviceContext.getDeviceInfo().getNodeId(), e);
59 return Futures.immediateFailedFuture(new ConnectionException(
60 "Failed to write node " + deviceContext.getDeviceInfo().getNodeId() + " to DS ", e));
63 // Get information about device
64 return initializeNodeInformation(deviceContext, switchFeaturesMandatory, skipTableFeatures,
65 multipartWriterProvider, convertorExecutor);
68 protected abstract Future<Void> initializeNodeInformation(@Nonnull DeviceContext deviceContext,
69 boolean switchFeaturesMandatory,
70 boolean skipTableFeatures,
71 @Nullable MultipartWriterProvider multipartWriterProvider,
72 @Nullable ConvertorExecutor convertorExecutor);