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
8 package org.opendaylight.openflowplugin.impl.device.initialization;
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.Futures;
12 import java.util.Collections;
13 import java.util.concurrent.Future;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.openflowplugin.api.ConnectionException;
18 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
19 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public abstract class AbstractDeviceInitializer {
27 private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceInitializer.class);
30 * Perform initial information gathering and store them to operational datastore.
32 * @param deviceContext device context
33 * @param switchFeaturesMandatory is switch features mandatory
34 * @param skipTableFeatures skip collecting of table features
35 * @param multipartWriterProvider multipart writer provider
36 * @param convertorExecutor convertor executor
38 @SuppressWarnings("checkstyle:IllegalCatch")
39 public Future<Void> initialize(@NonNull final DeviceContext deviceContext,
40 final boolean switchFeaturesMandatory,
41 final boolean skipTableFeatures,
42 @Nullable final MultipartWriterProvider multipartWriterProvider,
43 @Nullable final ConvertorExecutor convertorExecutor) {
44 Preconditions.checkNotNull(deviceContext);
46 // Write node to datastore
47 LOG.debug("Initializing node information for node {}", deviceContext.getDeviceInfo());
49 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, deviceContext
51 .getNodeInstanceIdentifier(),
53 .setId(deviceContext.getDeviceInfo().getNodeId())
54 .setNodeConnector(Collections.emptyList())
56 } catch (final Exception e) {
57 LOG.warn("Failed to write node {} to DS ", deviceContext.getDeviceInfo().getNodeId(), e);
58 return Futures.immediateFailedFuture(new ConnectionException(
59 "Failed to write node " + deviceContext.getDeviceInfo().getNodeId() + " to DS ", e));
62 // Get information about device
63 return initializeNodeInformation(deviceContext, switchFeaturesMandatory, skipTableFeatures,
64 multipartWriterProvider, convertorExecutor);
67 protected abstract Future<Void> initializeNodeInformation(@NonNull DeviceContext deviceContext,
68 boolean switchFeaturesMandatory,
69 boolean skipTableFeatures,
70 @Nullable MultipartWriterProvider multipartWriterProvider,
71 @Nullable ConvertorExecutor convertorExecutor);