Add ability to remove patches
Change-Id: Ia777213f4e1a5c3f7b3b583b932dfea7590076f1
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchListCommand.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchListCommand.java
new file mode 100644
index 0000000..9d8f088
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchListCommand.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/**
+ * This class defines the cli command for the PatchPanel class. It creates
+ * an instance of the PatchPanelService class to call it's method addPatch().
+ * The command takes 2 parameters, 2 connectPoints.
+ */
+package org.onosproject.patchpanel.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.patchpanel.impl.Patch;
+import org.onosproject.patchpanel.impl.PatchPanelService;
+
+/**
+ * Lists the patches.
+ */
+@Command(scope = "onos", name = "patches",
+ description = "Lists the patches")
+public class PatchListCommand extends AbstractShellCommand {
+
+ private static final String FORMAT = "%s: %s <-> %s";
+
+ @Override
+ protected void execute() {
+ PatchPanelService patchPanelService = get(PatchPanelService.class);
+
+ patchPanelService.getPatches().forEach(this::print);
+ }
+
+ private void print(Patch patch) {
+ print(FORMAT, patch.id(), patch.port1(), patch.port2());
+ }
+
+}
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchRemoveCommand.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchRemoveCommand.java
new file mode 100644
index 0000000..429cd50
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchRemoveCommand.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/**
+ * This class defines the cli command for the PatchPanel class. It creates
+ * an instance of the PatchPanelService class to call it's method addPatch().
+ * The command takes 2 parameters, 2 connectPoints.
+ */
+package org.onosproject.patchpanel.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.patchpanel.impl.PatchId;
+import org.onosproject.patchpanel.impl.PatchPanelService;
+
+/**
+ * Removes a patch.
+ */
+@Command(scope = "onos", name = "patch-remove",
+ description = "Removes a patch")
+public class PatchRemoveCommand extends AbstractShellCommand {
+
+ @Argument(index = 0, name = "patchId", description = "ID of patch to remove",
+ required = true, multiValued = false)
+ String id = null;
+
+ private PatchPanelService patchPanelService;
+
+ @Override
+ protected void execute() {
+ patchPanelService = get(PatchPanelService.class);
+ boolean done = false;
+
+ PatchId patchId = PatchId.patchId(Integer.parseInt(id));
+
+ done = patchPanelService.removePatch(patchId);
+
+ if (done) {
+ log.info("This patch has been removed");
+ } else {
+ log.info("This patch was NOT removed");
+ }
+
+ }
+
+}