blob: 13524d6d3641e37a516b9011e36636eaa9fb50dd [file] [log] [blame]
Jian Li16f1f532018-12-27 17:45:09 +09001/*
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.openstacktelemetry.cli;
17
18import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.Completion;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.openstacktelemetry.api.TelemetryConfigAdminService;
24import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
25
26/**
27 * Disables a telemetry service.
28 */
29@Service
30@Command(scope = "onos", name = "telemetry-disable",
31 description = "Disable a specific telemetry service")
32public class TelemetryServiceDisableCommand extends AbstractShellCommand {
33
34 @Argument(index = 0, name = "config name", description = "telemetry config name",
35 required = true, multiValued = false)
36 @Completion(TelemetryConfigNameCompleter.class)
37 private String configName = null;
38
39 private static final String FORMAT = "Successfully disabled telemetry service %s!";
40 private static final String NO_ELEMENT =
41 "No telemetry config is found with the given name";
42
43 @Override
44 protected void doExecute() {
45 TelemetryConfigAdminService service = get(TelemetryConfigAdminService.class);
46 TelemetryConfig config = service.getConfig(configName);
47
48 if (config == null) {
49 print(NO_ELEMENT);
50 return;
51 }
52
53 TelemetryConfig updatedConfig = config.updateEnabled(false);
54
55 service.updateTelemetryConfig(updatedConfig);
56 print(FORMAT, config.name());
57 }
58}