2 * Copyright (c) 2015 Huawei, Inc. 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.nemo.tool.sandbox.models;
11 import org.opendaylight.nemo.tool.sandbox.CmdExecutor;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 import java.util.ArrayList;
16 import java.util.List;
19 * Created by hj on 12/8/15.
21 abstract public class Node {
22 private static Logger log = LoggerFactory.getLogger(Node.class);
23 private final String name;
24 private final NodeType nodeType;
25 protected List<Connector> connectors;
27 public Node(NodeType nodeType, String name) {
28 this.nodeType = nodeType;
30 this.connectors = new ArrayList<Connector>();
33 public NodeType getNodeType() {
37 public String getName() {
41 public void addConnectors(Connector connector) {
42 connectors.add(connector);
45 public List<Connector> getConnectors() {
49 public void install() {
50 List<String> commands = generateCommands();
51 if (commands == null) {
52 log.error("Commands should not be null.");
55 for (String command : commands) {
57 CmdExecutor.sshExecute(command);
58 } catch (Exception e) {
59 log.error("Error while execute [{}].", command, name, nodeType);
65 abstract protected List<String> generateCommands();
68 public boolean equals(Object o) {
69 if (this == o) return true;
70 if (o == null || getClass() != o.getClass()) return false;
74 if (name != null ? !name.equals(node.name) : node.name != null) return false;
75 if (nodeType != node.nodeType) return false;
81 public int hashCode() {
82 int result = name != null ? name.hashCode() : 0;
83 result = 31 * result + (nodeType != null ? nodeType.hashCode() : 0);