blob: e484b488a373970473849fb720fd2303d245f001 [file] [log] [blame]
/*
* Copyright 2018-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.openstacktelemetry.cli;
import org.apache.karaf.shell.api.action.Argument;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.openstacktelemetry.api.TelemetryConfigAdminService;
import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
/**
* Enables a telemetry service.
*/
@Service
@Command(scope = "onos", name = "telemetry-enable",
description = "Enable a specific telemetry service")
public class TelemetryServiceEnableCommand extends AbstractShellCommand {
@Argument(index = 0, name = "config name", description = "telemetry config name",
required = true, multiValued = false)
@Completion(TelemetryConfigNameCompleter.class)
private String configName = null;
private static final String FORMAT = "Successfully enabled telemetry service %s!";
private static final String NO_ELEMENT =
"No telemetry config is found with the given name";
@Override
protected void doExecute() {
TelemetryConfigAdminService service = get(TelemetryConfigAdminService.class);
TelemetryConfig config = service.getConfig(configName);
if (config == null) {
print(NO_ELEMENT);
return;
}
TelemetryConfig updatedConfig = config.updateEnabled(true);
service.updateTelemetryConfig(updatedConfig);
print(FORMAT, config.name());
}
}