protected Object doExecute()

in features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java [71:151]


    protected Object doExecute() throws Exception {
        // check if the group exists
        Group group = groupManager.findGroupByName(groupName);
        if (group == null) {
            System.err.println("Cluster group " + groupName + " doesn't exist");
            return null;
        }

        // check if the producer is ON
        if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
            System.err.println("Cluster event producer is OFF");
            return null;
        }

        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        try {

            // get cluster feature
            Map<String, FeatureState> clusterFeatures = clusterManager.getMap(Constants.FEATURES_MAP + Configurations.SEPARATOR + groupName);

            CellarSupport support = new CellarSupport();
            support.setClusterManager(clusterManager);
            support.setConfigurationAdmin(configurationAdmin);
            support.setGroupManager(groupManager);

            for (String feature : features) {
                String[] split = feature.split("/");
                String name = split[0];
                String version = null;
                if (split.length == 2) {
                    // use the version provided by the user
                    version = split[1];
                }

                FeatureState found = null;
                String foundKey = null;
                for (String k : clusterFeatures.keySet()) {
                    FeatureState f = clusterFeatures.get(k);
                    foundKey = k;
                    if (version == null) {
                        if (f.getName().equals(name)) {
                            found = f;
                            break;
                        }
                    } else {
                        if (f.getName().equals(name) && f.getVersion().equals(version)) {
                            found = f;
                            break;
                        }
                    }
                }
                if (found == null) {
                    if (version == null)
                        throw new IllegalArgumentException("Feature " + name + " doesn't exist in cluster group " + groupName);
                    else
                        throw new IllegalArgumentException("Feature " + name + "/" + version + " doesn't exist in cluster group " + groupName);
                }

                // check if the feature is allowed
                if (support.isAllowed(group, Constants.CATEGORY, found.getName(), EventType.OUTBOUND)) {

                    // update the cluster group
                    found.setInstalled(true);
                    clusterFeatures.put(foundKey, found);

                    // broadcast the cluster event
                    ClusterFeaturesEvent event = new ClusterFeaturesEvent(found.getName(), found.getVersion(), noRefresh, noStart, noManage, upgrade, FeatureEvent.EventType.FeatureInstalled);
                    event.setSourceGroup(group);
                    eventProducer.produce(event);
                } else {
                    System.err.println("Feature name " + found.getName() + " is blocked outbound for cluster group " + groupName);
                }
            }
        } finally {
            Thread.currentThread().setContextClassLoader(originalClassLoader);
        }

        return null;
    }