blob: ff0895eee162419dbfbd3761bb6edec361fd746b [file] [log] [blame]
Charles Chan33f4a912018-04-19 23:35:30 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli.net;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Charles Chan33f4a912018-04-19 23:35:30 -070021import org.onlab.osgi.ServiceNotFoundException;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.flowobjective.FlowObjectiveService;
24
25/**
26 * Clear flow objective that are waiting for the completion of previous objective with the same key.
27 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070028@Service
Charles Chan33f4a912018-04-19 23:35:30 -070029@Command(scope = "onos", name = "obj-clear-queues",
30 description = "Force empty flow objective queues and invalidate flow objective caches")
31public class FlowObjectiveQueueClearCommand extends AbstractShellCommand {
32
33 private static final String CONFIRM_PHRASE = "please";
34 @Argument(name = "confirm", description = "Confirmation phrase")
35 private String please = null;
36
37 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070038 protected void doExecute() {
Charles Chan33f4a912018-04-19 23:35:30 -070039 if (please == null || !please.equals(CONFIRM_PHRASE)) {
40 print("WARNING: System may enter an unpredictable state if the flow obj queues are force emptied." +
41 "Enter confirmation phrase to continue.");
42 return;
43 }
44
45 try {
46 FlowObjectiveService service = get(FlowObjectiveService.class);
47 service.clearQueue();
48 } catch (ServiceNotFoundException e) {
49 print("FlowObjectiveService unavailable");
50 }
51 }
52
53}