diff options
Diffstat (limited to 'framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg')
7 files changed, 0 insertions, 508 deletions
diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentConfigCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentConfigCommand.java deleted file mode 100644 index 5b9a7283..00000000 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentConfigCommand.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2015 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. - */ -package org.onosproject.cli.cfg; - -import java.util.Optional; -import java.util.Set; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.cfg.ConfigProperty; -import org.onosproject.cli.AbstractShellCommand; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Strings.isNullOrEmpty; - -/** - * Manages component configuration. - */ -@Command(scope = "onos", name = "cfg", - description = "Manages component configuration") -public class ComponentConfigCommand extends AbstractShellCommand { - - static final String GET = "get"; - static final String SET = "set"; - - private static final String FMT = " name=%s, type=%s, value=%s, defaultValue=%s, description=%s"; - private static final String SHORT_FMT = " %s=%s"; - - @Option(name = "-s", aliases = "--short", description = "Show short output only", - required = false, multiValued = false) - private boolean shortOnly = false; - - - @Argument(index = 0, name = "command", - description = "Command name (get|set)", - required = false, multiValued = false) - String command = null; - - @Argument(index = 1, name = "component", description = "Component name", - required = false, multiValued = false) - String component = null; - - @Argument(index = 2, name = "name", description = "Property name", - required = false, multiValued = false) - String name = null; - - @Argument(index = 3, name = "value", description = "Property value", - required = false, multiValued = false) - String value = null; - - ComponentConfigService service; - - @Override - protected void execute() { - service = get(ComponentConfigService.class); - if (isNullOrEmpty(command)) { - listComponents(); - } else if (command.equals(GET) && isNullOrEmpty(component)) { - listAllComponentsProperties(); - } else if (command.equals(GET) && isNullOrEmpty(name)) { - listComponentProperties(component); - } else if (command.equals(GET)) { - listComponentProperty(component, name); - } else if (command.equals(SET) && isNullOrEmpty(value)) { - service.unsetProperty(component, name); - } else if (command.equals(SET)) { - service.setProperty(component, name, value); - } else { - error("Illegal usage"); - } - } - - private void listAllComponentsProperties() { - if (outputJson()) { - print("%s", jsonComponentProperties()); - } else { - service.getComponentNames().forEach(this::listComponentProperties); - } - } - - private JsonNode jsonProperty(ConfigProperty configProperty, ObjectMapper mapper) { - return mapper.createObjectNode() - .put("name", configProperty.name()) - .put("type", configProperty.type().toString().toLowerCase()) - .put("value", configProperty.value()) - .put("defaultValue", configProperty.defaultValue()) - .put("description", configProperty.description()); - } - - private JsonNode jsonComponent(String component, ObjectMapper mapper) { - ObjectNode node = mapper.createObjectNode() - .put("componentName", component); - final ArrayNode propertiesJson = node.putArray("properties"); - Set<ConfigProperty> properties = service.getProperties(component); - if (properties != null) { - properties.forEach(configProperty -> propertiesJson.add( - jsonProperty(configProperty, mapper))); - } - return node; - } - - private JsonNode jsonComponentProperties() { - ObjectMapper mapper = new ObjectMapper(); - ArrayNode result = mapper.createArrayNode(); - service.getComponentNames() - .forEach(component -> result.add(jsonComponent(component, mapper))); - - return result; - } - - private void listComponents() { - if (outputJson()) { - ArrayNode node = new ObjectMapper().createArrayNode(); - service.getComponentNames().forEach(node::add); - print("%s", node); - } else { - service.getComponentNames().forEach(n -> print("%s", n)); - } - } - - private void listComponentProperties(String component) { - if (outputJson()) { - print("%s", jsonComponent(component, new ObjectMapper())); - } else { - Set<ConfigProperty> props = service.getProperties(component); - print("%s", component); - if (props == null) { - print("No properties for component " + component + " found"); - } else if (shortOnly) { - props.forEach(p -> print(SHORT_FMT, p.name(), p.value())); - } else { - props.forEach(p -> print(FMT, p.name(), p.type().toString().toLowerCase(), - p.value(), p.defaultValue(), p.description())); - } - } - } - - private void listComponentProperty(String component, String name) { - Set<ConfigProperty> props = service.getProperties(component); - - if (props == null) { - return; - } - Optional<ConfigProperty> property = props.stream() - .filter(p -> p.name().equals(name)).findFirst(); - if (outputJson()) { - print("%s", jsonProperty(property.get(), new ObjectMapper())); - } else { - if (!property.isPresent()) { - print("Property " + name + " for component " + component + " not found"); - return; - } - ConfigProperty p = property.get(); - if (shortOnly) { - print(SHORT_FMT, p.name(), p.value()); - } else { - print(FMT, p.name(), p.type().toString().toLowerCase(), p.value(), - p.defaultValue(), p.description()); - } - } - } - -} diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentConfigCommandCompleter.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentConfigCommandCompleter.java deleted file mode 100644 index 5506d816..00000000 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentConfigCommandCompleter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2015 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. - */ -package org.onosproject.cli.cfg; - -import org.apache.karaf.shell.console.Completer; -import org.apache.karaf.shell.console.completer.StringsCompleter; - -import java.util.List; -import java.util.SortedSet; - -import static org.onosproject.cli.cfg.ComponentConfigCommand.GET; -import static org.onosproject.cli.cfg.ComponentConfigCommand.SET; - -/** - * Component configuration command completer. - */ -public class ComponentConfigCommandCompleter implements Completer { - @Override - public int complete(String buffer, int cursor, List<String> candidates) { - // Delegate string completer - StringsCompleter delegate = new StringsCompleter(); - SortedSet<String> strings = delegate.getStrings(); - strings.add(GET); - strings.add(SET); - - // Now let the completer do the work for figuring out what to offer. - return delegate.complete(buffer, cursor, candidates); - } - -} diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentNameCompleter.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentNameCompleter.java deleted file mode 100644 index 4883b991..00000000 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentNameCompleter.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2015 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. - */ -package org.onosproject.cli.cfg; - -import org.apache.karaf.shell.console.Completer; -import org.apache.karaf.shell.console.completer.StringsCompleter; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.cli.AbstractShellCommand; - -import java.util.List; -import java.util.SortedSet; - -/** - * Component name completer. - */ -public class ComponentNameCompleter implements Completer { - @Override - public int complete(String buffer, int cursor, List<String> candidates) { - // Delegate string completer - StringsCompleter delegate = new StringsCompleter(); - - // Fetch our service and feed it's offerings to the string completer - ComponentConfigService service = AbstractShellCommand.get(ComponentConfigService.class); - SortedSet<String> strings = delegate.getStrings(); - service.getComponentNames().forEach(strings::add); - - // Now let the completer do the work for figuring out what to offer. - return delegate.complete(buffer, cursor, candidates); - } - -} diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentPropertyNameCompleter.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentPropertyNameCompleter.java deleted file mode 100644 index 98e19690..00000000 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/ComponentPropertyNameCompleter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2015 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. - */ -package org.onosproject.cli.cfg; - -import org.apache.karaf.shell.console.completer.ArgumentCompleter; -import org.apache.karaf.shell.console.completer.StringsCompleter; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.cfg.ConfigProperty; -import org.onosproject.cli.AbstractCompleter; - -import java.util.List; -import java.util.Set; -import java.util.SortedSet; - -import static org.onosproject.cli.AbstractShellCommand.get; - -/** - * Component property name completer. - */ -public class ComponentPropertyNameCompleter extends AbstractCompleter { - @Override - public int complete(String buffer, int cursor, List<String> candidates) { - // Delegate string completer - StringsCompleter delegate = new StringsCompleter(); - - // Component name is the previous argument. - ArgumentCompleter.ArgumentList list = getArgumentList(); - String componentName = list.getArguments()[list.getCursorArgumentIndex() - 1]; - ComponentConfigService service = get(ComponentConfigService.class); - - SortedSet<String> strings = delegate.getStrings(); - Set<ConfigProperty> properties = - service.getProperties(componentName); - if (properties != null) { - properties.forEach(property -> strings.add(property.name())); - } - - // Now let the completer do the work for figuring out what to offer. - return delegate.complete(buffer, cursor, candidates); - } - -} diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java deleted file mode 100644 index 7ce56692..00000000 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2015 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. - */ -package org.onosproject.cli.cfg; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.net.config.Config; -import org.onosproject.net.config.NetworkConfigService; -import org.onosproject.net.config.SubjectFactory; - -import static com.google.common.base.Strings.isNullOrEmpty; - -/** - * Manages network configuration. - */ -@Command(scope = "onos", name = "netcfg", - description = "Manages network configuration") -public class NetworkConfigCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "subjectClassKey", description = "Subject class key", - required = false, multiValued = false) - String subjectClassKey = null; - - @Argument(index = 1, name = "subjectKey", description = "Subject key", - required = false, multiValued = false) - String subjectKey = null; - - @Argument(index = 2, name = "configKey", description = "Config key", - required = false, multiValued = false) - String configKey = null; - - private final ObjectMapper mapper = new ObjectMapper(); - private NetworkConfigService service; - - @Override - protected void execute() { - service = get(NetworkConfigService.class); - JsonNode root = mapper.createObjectNode(); - if (isNullOrEmpty(subjectClassKey)) { - addAll((ObjectNode) root); - } else { - SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey); - if (isNullOrEmpty(subjectKey)) { - addSubjectClass((ObjectNode) root, subjectFactory); - } else { - Object s = subjectFactory.createSubject(subjectKey); - if (isNullOrEmpty(configKey)) { - addSubject((ObjectNode) root, s); - } else { - root = getSubjectConfig(getConfig(s, subjectClassKey, configKey)); - } - } - } - - try { - print("%s", mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root)); - } catch (JsonProcessingException e) { - throw new RuntimeException("Error writing JSON to string", e); - } - } - - @SuppressWarnings("unchecked") - private void addAll(ObjectNode root) { - service.getSubjectClasses() - .forEach(sc -> { - SubjectFactory sf = service.getSubjectFactory(sc); - addSubjectClass(newObject(root, sf.subjectClassKey()), sf); - }); - } - - @SuppressWarnings("unchecked") - private void addSubjectClass(ObjectNode root, SubjectFactory sf) { - service.getSubjects(sf.subjectClass()) - .forEach(s -> addSubject(newObject(root, sf.subjectKey(s)), s)); - } - - private void addSubject(ObjectNode root, Object s) { - service.getConfigs(s).forEach(c -> root.set(c.key(), c.node())); - } - - private JsonNode getSubjectConfig(Config config) { - return config != null ? config.node() : null; - } - - private Config getConfig(Object s, String subjectKey, String ck) { - Class<? extends Config> configClass = service.getConfigClass(subjectKey, ck); - return configClass != null ? service.getConfig(s, configClass) : null; - } - - private ObjectNode newObject(ObjectNode parent, String key) { - ObjectNode node = mapper.createObjectNode(); - parent.set(key, node); - return node; - } -} diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigRegistryCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigRegistryCommand.java deleted file mode 100644 index cf588770..00000000 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigRegistryCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015 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. - */ -package org.onosproject.cli.cfg; - -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.net.config.ConfigFactory; -import org.onosproject.net.config.NetworkConfigRegistry; - -/** - * Displays network configuration registry contents. - */ -@Command(scope = "onos", name = "netcfg-registry", - description = "Displays network configuration registry contents") -public class NetworkConfigRegistryCommand extends AbstractShellCommand { - - private static final String FMT = "subjectKey=%s, configKey=%s, subjectClass=%s, configClass=%s"; - private static final String SHORT_FMT = "%-12s %-12s %-40s %s"; - - @Option(name = "-s", aliases = "--short", description = "Show short output only", - required = false, multiValued = false) - private boolean shortOnly = false; - - @Override - protected void execute() { - get(NetworkConfigRegistry.class).getConfigFactories().forEach(this::print); - } - - private void print(ConfigFactory configFactory) { - print(shortOnly ? SHORT_FMT : FMT, - configFactory.subjectFactory().subjectClassKey(), - configFactory.configKey(), - configFactory.subjectFactory().subjectClass().getName(), - configFactory.configClass().getName()); - } - -} diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/package-info.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/package-info.java deleted file mode 100644 index 0891ddb5..00000000 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 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. - */ - -/** - * CLI commands for managing centralized component and network configurations. - */ -package org.onosproject.cli.cfg;
\ No newline at end of file |