[ONOS-7732] Automating switch workflow

Change-Id: Ie047c34df2278bc2220cade744f51ca6950f48f6
diff --git a/apps/workflow/model/BUCK b/apps/workflow/model/BUCK
new file mode 100644
index 0000000..a1c6f0b
--- /dev/null
+++ b/apps/workflow/model/BUCK
@@ -0,0 +1,12 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:jackson-core',
+    '//lib:jackson-annotations',
+    '//lib:jackson-databind',
+    '//core/store/serializers:onos-core-serializers',
+    '//apps/workflow/api:onos-apps-workflow-api',
+]
+
+osgi_jar_with_tests(
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/workflow/model/BUILD b/apps/workflow/model/BUILD
new file mode 100644
index 0000000..016e14a
--- /dev/null
+++ b/apps/workflow/model/BUILD
@@ -0,0 +1,8 @@
+COMPILE_DEPS = CORE_DEPS + KRYO + JACKSON + [
+    "//core/store/serializers:onos-core-serializers",
+    "//apps/workflow/api:onos-apps-workflow-api",
+]
+
+osgi_jar_with_tests(
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/NetconfAccessInfo.java b/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/NetconfAccessInfo.java
new file mode 100644
index 0000000..8e428e3
--- /dev/null
+++ b/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/NetconfAccessInfo.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.workflow.model.accessinfo;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.NumericNode;
+import com.fasterxml.jackson.databind.node.TextNode;
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+import org.onosproject.workflow.api.WorkflowException;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Class for NETCONF access information.
+ */
+public final class NetconfAccessInfo {
+
+    private static final String REMOTE_IP = "remoteIp";
+    private static final String PORT = "port";
+    private static final String USER = "user";
+    private static final String PASSWORD = "password";
+
+    private final IpAddress remoteIp;
+    private final TpPort port;
+    private final String user;
+    private final String password;
+
+    /**
+     * Constructor for a given NETCONF access information.
+     *
+     * @param remoteIp remote ip address
+     * @param port port number
+     * @param user user name
+     * @param password password
+     */
+    public NetconfAccessInfo(IpAddress remoteIp,
+                             TpPort port,
+                             String user,
+                             String password) {
+        this.remoteIp = checkNotNull(remoteIp);
+        this.port = checkNotNull(port);
+        this.user = checkNotNull(user);
+        this.password = checkNotNull(password);
+    }
+
+    /**
+     * Builds NetconfAccessInfo from json.
+     * @param root json root node for NetconfAccessinfo
+     * @return NETCONF access information
+     * @throws WorkflowException workflow exception
+     */
+    public static NetconfAccessInfo valueOf(JsonNode root) throws WorkflowException {
+
+        JsonNode node = root.at(ptr(REMOTE_IP));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid remoteIp for " + root);
+        }
+        IpAddress remoteIp = IpAddress.valueOf(node.asText());
+
+        node = root.at(ptr(PORT));
+        if (node == null || !(node instanceof NumericNode)) {
+            throw new WorkflowException("invalid port for " + root);
+        }
+        TpPort tpPort = TpPort.tpPort(node.asInt());
+
+        node = root.at(ptr(USER));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid user for " + root);
+        }
+        String strUser = node.asText();
+
+        node = root.at(ptr(PASSWORD));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid password for " + root);
+        }
+        String strPassword = node.asText();
+
+        return new NetconfAccessInfo(remoteIp, tpPort, strUser, strPassword);
+    }
+
+    private static String ptr(String field) {
+        return "/" + field;
+    }
+
+    /**
+     * Returns the remote IP address.
+     *
+     * @return ip address
+     */
+    public IpAddress remoteIp() {
+        return this.remoteIp;
+    }
+
+    /**
+     * Returns the port number.
+     *
+     * @return port
+     */
+    public TpPort port() {
+        return this.port;
+    }
+
+    /**
+     * Returns the user name.
+     *
+     * @return user name
+     */
+    public String user() {
+        return this.user;
+    }
+
+    /**
+     * Returns the password.
+     * @return password
+     */
+    public String password() {
+        return this.password;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj instanceof NetconfAccessInfo) {
+            NetconfAccessInfo that = (NetconfAccessInfo) obj;
+            return Objects.equals(remoteIp, that.remoteIp) &&
+                    Objects.equals(port, that.port) &&
+                    Objects.equals(user, that.user);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(remoteIp, port, user);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("remoteIp", remoteIp)
+                .add("port", port)
+                .add("user", user)
+                .toString();
+    }
+}
\ No newline at end of file
diff --git a/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/RestAccessInfo.java b/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/RestAccessInfo.java
new file mode 100644
index 0000000..c13270d
--- /dev/null
+++ b/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/RestAccessInfo.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.workflow.model.accessinfo;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.NumericNode;
+import com.fasterxml.jackson.databind.node.TextNode;
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+import org.onosproject.workflow.api.WorkflowException;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Class for REST access information.
+ */
+public final class RestAccessInfo {
+
+    private static final String REMOTE_IP = "remoteIp";
+    private static final String PORT = "port";
+    private static final String USER = "user";
+    private static final String PASSWORD = "password";
+
+    private final IpAddress remoteIp;
+    private final TpPort port;
+    private final String user;
+    private String password;
+
+    /**
+     * Creates a new REST access information.
+     *
+     * @param remoteIp remote ip address
+     * @param port port number
+     * @param user user name
+     * @param password password
+     */
+    private RestAccessInfo(IpAddress remoteIp,
+                          TpPort port,
+                          String user,
+                          String password) {
+        this.remoteIp = checkNotNull(remoteIp);
+        this.port = checkNotNull(port);
+        this.user = checkNotNull(user);
+        this.password = checkNotNull(password);
+    }
+
+    /**
+     * Builds RestAccessInfo from json.
+     * @param root json root node for RestAccessinfo
+     * @return REST access information
+     * @throws WorkflowException workflow exception
+     */
+    public static RestAccessInfo valueOf(JsonNode root) throws WorkflowException {
+
+        JsonNode node = root.at(ptr(REMOTE_IP));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid remoteIp for " + root);
+        }
+        IpAddress remoteIp = IpAddress.valueOf(node.asText());
+
+        node = root.at(ptr(PORT));
+        if (node == null || !(node instanceof NumericNode)) {
+            throw new WorkflowException("invalid port for " + root);
+        }
+        TpPort tpPort = TpPort.tpPort(node.asInt());
+
+        node = root.at(ptr(USER));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid user for " + root);
+        }
+        String strUser = node.asText();
+
+        node = root.at(ptr(PASSWORD));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid password for " + root);
+        }
+        String strPassword = node.asText();
+
+        return new RestAccessInfo(remoteIp, tpPort, strUser, strPassword);
+    }
+
+    private static String ptr(String field) {
+        return "/" + field;
+    }
+
+    /**
+     * Returns the remote IP address.
+     *
+     * @return ip address
+     */
+    public IpAddress remoteIp() {
+        return this.remoteIp;
+    }
+
+    /**
+     * Returns the port number.
+     *
+     * @return REST port
+     */
+    public TpPort port() {
+        return this.port;
+    }
+
+    /**
+     * Returns the user name.
+     *
+     * @return user name
+     */
+    public String user() {
+        return this.user;
+    }
+
+    /**
+     * Returns the password.
+     *
+     * @return password
+     */
+    public String password() {
+        return this.password;
+    }
+
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj instanceof RestAccessInfo) {
+            RestAccessInfo that = (RestAccessInfo) obj;
+            return Objects.equals(remoteIp, that.remoteIp) &&
+                    Objects.equals(port, that.port) &&
+                    Objects.equals(user, that.user);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(remoteIp, port, user);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("remoteIp", remoteIp)
+                .add("port", port)
+                .add("user", user)
+                .toString();
+    }
+}
\ No newline at end of file
diff --git a/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/SshAccessInfo.java b/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/SshAccessInfo.java
new file mode 100644
index 0000000..aec224a
--- /dev/null
+++ b/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/SshAccessInfo.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.workflow.model.accessinfo;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.NumericNode;
+import com.fasterxml.jackson.databind.node.TextNode;
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+import org.onosproject.workflow.api.WorkflowException;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Class for SSH access information.
+ */
+public final class SshAccessInfo {
+
+    private static final String REMOTE_IP = "remoteIp";
+    private static final String PORT = "port";
+    private static final String USER = "user";
+    private static final String PASSWORD = "password";
+    private static final String KEYFILE = "keyfile";
+
+    private final IpAddress remoteIp;
+    private final TpPort port;
+    private final String user;
+    private String password;
+    private final String privateKey;
+
+    /**
+     * Constructor for SSH access information.
+     *
+     * @param remoteIp ssh remote ip address
+     * @param port ssh port number
+     * @param user user name
+     * @param password password
+     * @param privateKey path of ssh private key
+     */
+    private SshAccessInfo(IpAddress remoteIp, TpPort port, String user, String password, String privateKey) {
+        this.remoteIp = checkNotNull(remoteIp);
+        this.port = checkNotNull(port);
+        this.user = checkNotNull(user);
+        this.password = password;
+        this.privateKey = checkNotNull(privateKey);
+    }
+
+    /**
+     * Builds SshAccessInfo from json.
+     * @param root json root node for SshAccessinfo
+     * @return SSH access information
+     * @throws WorkflowException workflow exception
+     */
+    public static SshAccessInfo valueOf(JsonNode root) throws WorkflowException {
+
+        JsonNode node = root.at(ptr(REMOTE_IP));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid remoteIp for " + root);
+        }
+        IpAddress sshIp = IpAddress.valueOf(node.asText());
+
+        node = root.at(ptr(PORT));
+        if (node == null || !(node instanceof NumericNode)) {
+            throw new WorkflowException("invalid port for " + root);
+        }
+        TpPort sshPort = TpPort.tpPort(node.asInt());
+
+        node = root.at(ptr(USER));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid user for " + root);
+        }
+        String sshUser = node.asText();
+
+        node = root.at(ptr(PASSWORD));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid password for " + root);
+        }
+        String sshPassword = node.asText();
+
+        node = root.at(ptr(KEYFILE));
+        if (node == null || !(node instanceof TextNode)) {
+            throw new WorkflowException("invalid keyfile for " + root);
+        }
+        String sshKeyfile = node.asText();
+
+        return new SshAccessInfo(sshIp, sshPort, sshUser, sshPassword, sshKeyfile);
+    }
+
+    private static String ptr(String field) {
+        return "/" + field;
+    }
+
+    /**
+     * Returns the remote IP address.
+     *
+     * @return ip address
+     */
+    public IpAddress remoteIp() {
+        return this.remoteIp;
+    }
+
+    /**
+     * Returns the port number.
+     *
+     * @return ssh port
+     */
+    public TpPort port() {
+        return this.port;
+    }
+
+    /**
+     * Returns the user name.
+     *
+     * @return user name
+     */
+    public String user() {
+        return this.user;
+    }
+
+    /**
+     * Returns the password.
+     * @return password
+     */
+    public String password() {
+        return this.password;
+    }
+
+    /**
+     * Returns the private key path.
+     *
+     * @return privateKey
+     */
+    public String privateKey() {
+        return privateKey;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj instanceof SshAccessInfo) {
+            SshAccessInfo that = (SshAccessInfo) obj;
+            return Objects.equals(remoteIp, that.remoteIp) &&
+                    Objects.equals(port, that.port) &&
+                    Objects.equals(user, that.user) &&
+                    Objects.equals(privateKey, that.privateKey);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(remoteIp, port, user, privateKey);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("remoteIp", remoteIp)
+                .add("port", port)
+                .add("user", user)
+                .add("privateKey", privateKey)
+                .toString();
+    }
+}
diff --git a/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/package-info.java b/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/package-info.java
new file mode 100644
index 0000000..bc88e3b
--- /dev/null
+++ b/apps/workflow/model/src/main/java/org/onosproject/workflow/model/accessinfo/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Package for workflow common data model - access info.
+ */
+package org.onosproject.workflow.model.accessinfo;