Search in sources :

Example 1 with ConfigInfo

use of org.jboss.galleon.cli.model.ConfigInfo in project galleon by wildfly.

the class FeatureContainerPathConsumer method enterConfigurationName.

// @Override
public void enterConfigurationName(String name) throws PathConsumerException {
    List<ConfigInfo> configs = info.getFinalConfigs().get(configModel);
    for (ConfigInfo c : configs) {
        if (c.getName().equals(name)) {
            config = c;
            break;
        }
    }
    if (config == null) {
        if (completion) {
            if (inError) {
                throw new PathConsumerException("no config for name " + name);
            } else {
                inError = true;
            }
        } else {
            throw new PathConsumerException("no config for name " + name);
        }
    }
    configName = name;
    configModel = null;
}
Also used : ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo)

Example 2 with ConfigInfo

use of org.jboss.galleon.cli.model.ConfigInfo in project galleon by wildfly.

the class GetInfoCommand method displayConfigs.

private boolean displayConfigs(PmCommandInvocation commandInvocation, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
    Map<String, List<ConfigInfo>> configs = new HashMap<>();
    try (ProvisioningRuntime rt = ProvisioningRuntimeBuilder.newInstance(commandInvocation.getPmSession().getMessageWriter(false)).initRtLayout(pLayout.transform(ProvisioningRuntimeBuilder.FP_RT_FACTORY)).build()) {
        for (ProvisionedConfig m : rt.getConfigs()) {
            String model = m.getModel();
            List<ConfigInfo> names = configs.get(model);
            if (names == null) {
                names = new ArrayList<>();
                configs.put(model, names);
            }
            if (m.getName() != null) {
                names.add(new ConfigInfo(model, m.getName(), m.getLayers()));
            }
        }
        String str = StateInfoUtil.buildConfigs(configs, pLayout);
        if (str != null) {
            commandInvocation.print(str);
        }
        return str != null;
    }
}
Also used : HashMap(java.util.HashMap) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) ArrayList(java.util.ArrayList) List(java.util.List) ProvisionedConfig(org.jboss.galleon.state.ProvisionedConfig) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo)

Example 3 with ConfigInfo

use of org.jboss.galleon.cli.model.ConfigInfo in project galleon by wildfly.

the class StateInfoUtil method buildConfigs.

public static String buildConfigs(Map<String, List<ConfigInfo>> configs, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
    if (!configs.isEmpty()) {
        boolean hasLayers = false;
        List<Table.Node> nodes = new ArrayList<>();
        Map<String, Map<String, Set<String>>> layers = LayersConfigBuilder.getAllLayers(pLayout);
        for (Entry<String, List<ConfigInfo>> entry : configs.entrySet()) {
            if (!entry.getValue().isEmpty()) {
                Table.Node model = new Table.Node(entry.getKey());
                nodes.add(model);
                for (ConfigInfo name : entry.getValue()) {
                    Table.Node nameNode = new Table.Node(name.getName());
                    model.addNext(nameNode);
                    // Compute the direct dependencies only, remove dependencies of dependencies.
                    for (ConfigId id : name.getlayers()) {
                        Map<String, Set<String>> map = layers.get(entry.getKey());
                        boolean foundAsDependency = false;
                        if (map != null) {
                            for (ConfigId l : name.getlayers()) {
                                if (l.getName().equals(id.getName())) {
                                    continue;
                                }
                                Set<String> deps = map.get(l.getName());
                                if (deps != null) {
                                    if (deps.contains(id.getName())) {
                                        foundAsDependency = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!foundAsDependency) {
                            hasLayers = true;
                            nameNode.addNext(new Table.Node(id.getName()));
                        }
                    }
                    ConfigModel m = pLayout.getConfig().getDefinedConfig(name.getId());
                    if (m != null) {
                        if (m.hasExcludedLayers()) {
                            for (String ex : m.getExcludedLayers()) {
                                hasLayers = true;
                                nameNode.addNext(new Table.Node(ex + "(excluded)"));
                            }
                        }
                    }
                }
            }
        }
        Table.Tree table;
        if (hasLayers) {
            table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME, Headers.LAYERS);
        } else {
            table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME);
        }
        table.addAll(nodes);
        return "Configurations" + Config.getLineSeparator() + table.build();
    }
    return null;
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) Set(java.util.Set) ArrayList(java.util.ArrayList) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo) ConfigModel(org.jboss.galleon.config.ConfigModel) List(java.util.List) ArrayList(java.util.ArrayList) ConfigId(org.jboss.galleon.config.ConfigId) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ConfigInfo

use of org.jboss.galleon.cli.model.ConfigInfo in project galleon by wildfly.

the class StateAddFeatureCommand method getConfiguration.

private ConfigInfo getConfiguration(State state) throws PathParserException, PathConsumerException, ProvisioningException {
    @SuppressWarnings("unchecked") List<String> args = (List<String>) getValue(ARGUMENT_NAME);
    String config = args.get(0);
    String path = FeatureContainerPathConsumer.FINAL_CONFIGS_PATH + config + PathParser.PATH_SEPARATOR;
    FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(state.getContainer(), false);
    PathParser.parse(path, consumer);
    ConfigInfo ci = consumer.getConfig();
    if (ci == null) {
        throw new ProvisioningException("Not a valid config " + config);
    }
    return ci;
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) ProvisioningException(org.jboss.galleon.ProvisioningException) ArrayList(java.util.ArrayList) List(java.util.List) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo)

Example 5 with ConfigInfo

use of org.jboss.galleon.cli.model.ConfigInfo in project galleon by wildfly.

the class StateRemoveFeatureCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc, State session) throws IOException, ProvisioningException, CommandExecutionException {
    try {
        String path = FeatureContainerPathConsumer.FINAL_CONFIGS_PATH + (feature.endsWith("" + PathParser.PATH_SEPARATOR) ? feature : feature + PathParser.PATH_SEPARATOR);
        FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(session.getContainer(), false);
        PathParser.parse(path, consumer);
        ConfigInfo ci = consumer.getConfig();
        if (ci == null) {
            throw new ProvisioningException("Not a valid configuration " + feature);
        }
        Group grp = consumer.getCurrentNode(path);
        if (grp == null) {
            throw new ProvisioningException("Not a valid feature " + feature);
        }
        FeatureInfo fi = grp.getFeature();
        if (fi == null) {
            throw new ProvisioningException("Not a valid feature " + feature);
        }
        session.removeFeature(invoc.getPmSession(), ci, fi);
    } catch (Exception ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.removeFeatureFailed(), ex);
    }
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) Group(org.jboss.galleon.cli.model.Group) ProvisioningException(org.jboss.galleon.ProvisioningException) FeatureInfo(org.jboss.galleon.cli.model.FeatureInfo) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo) IOException(java.io.IOException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Aggregations

ConfigInfo (org.jboss.galleon.cli.model.ConfigInfo)8 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)5 ProvisioningException (org.jboss.galleon.ProvisioningException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HashMap (java.util.HashMap)2 IOException (java.io.IOException)1 Map (java.util.Map)1 Set (java.util.Set)1 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)1 Table (org.jboss.galleon.cli.cmd.Table)1 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)1 FeatureInfo (org.jboss.galleon.cli.model.FeatureInfo)1 Group (org.jboss.galleon.cli.model.Group)1 PathConsumerException (org.jboss.galleon.cli.path.PathConsumerException)1 PathParserException (org.jboss.galleon.cli.path.PathParserException)1 ConfigId (org.jboss.galleon.config.ConfigId)1 ConfigModel (org.jboss.galleon.config.ConfigModel)1 ProvisioningRuntime (org.jboss.galleon.runtime.ProvisioningRuntime)1 ProvisionedConfig (org.jboss.galleon.state.ProvisionedConfig)1