blob: ea362471cab93a08e912083603e34fca5d2b8bc7 [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 com.google.common.collect.Maps;
19import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.Completion;
22import org.apache.karaf.shell.api.action.lifecycle.Service;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.openstacktelemetry.api.TelemetryConfigAdminService;
25import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
26
27import java.util.Map;
28
29/**
30 * Update telemetry configuration.
31 */
32@Service
33@Command(scope = "onos", name = "telemetry-update-address",
34 description = "Update a telemetry address")
35public class TelemetryConfigUpdateAddressCommand extends AbstractShellCommand {
36
37 @Argument(index = 0, name = "config name", description = "telemetry config name",
38 required = true, multiValued = false)
39 @Completion(TelemetryConfigNameCompleter.class)
40 private String configName = null;
41
42 @Argument(index = 1, name = "address", description = "telemetry config address",
43 required = true, multiValued = false)
44 private String address = null;
45
46 private static final String ADDRESS = "address";
47 private static final String NO_ELEMENT =
48 "No telemetry config is found with the given name";
49
50 @Override
51 protected void doExecute() {
52 TelemetryConfigAdminService service = get(TelemetryConfigAdminService.class);
53 TelemetryConfig config = service.getConfig(configName);
54
55 if (config == null) {
56 print(NO_ELEMENT);
57 return;
58 }
59
60 Map<String, String> updatedProperties = Maps.newHashMap(config.properties());
61 updatedProperties.put(ADDRESS, address);
62
63 TelemetryConfig updatedConfig = config.updateProperties(updatedProperties);
64
65 service.updateTelemetryConfig(updatedConfig);
66 print("Successfully updated telemetry config address!");
67 }
68}