protected Object doExecute()

in shell/src/main/java/org/apache/karaf/cellar/shell/SyncCommand.java [63:121]


    protected Object doExecute() throws Exception {
        boolean allResources = false;
        // if the user didn't provide any resource, we consider all
        if (!bundleSync && !configSync && !featuresSync && !obrSync) {
            allResources = true;
        }
        Set<Group> groups;
        if (groupName == null || groupName.isEmpty()) {
            groups = groupManager.listLocalGroups();
        } else {
            groups = new HashSet<Group>();
            if (groupManager.findGroupByName(groupName) == null) {
                System.err.println("Cluster group " + groupName + " doesn't exist");
                return null;
            }
            groups.add(groupManager.findGroupByName(groupName));
        }
        if (policy == null || policy.isEmpty()) {
            // we are in sync mode
            // constructing the target cluster groups
            for (Group group : groups) {
                System.out.println("Synchronizing cluster group " + group.getName());
                if (bundleSync || allResources) {
                    doSync("bundle", group);
                }
                if (configSync || allResources) {
                    doSync("config", group);
                }
                if (featuresSync || allResources) {
                    doSync("feature", group);
                }
                if (obrSync || allResources) {
                    doSync("obr.urls", group);
                }
            }
        } else {
            // we are in set mode
            if (!policy.equalsIgnoreCase("cluster") && !policy.equalsIgnoreCase("node") && !policy.equalsIgnoreCase("clusterOnly") && !policy.equalsIgnoreCase("nodeOnly") && !policy.equalsIgnoreCase("disabled")) {
                System.err.println("The sync policy " + policy + " is not valid. Valid sync policies are: cluster, node, clusterOnly, nodeOnly, disabled");
                return null;
            }
            for (Group group : groups) {
                System.out.println("Updating sync policy for cluster group " + group.getName());
                if (bundleSync || allResources) {
                    updateSync("bundle", group, policy);
                }
                if (configSync || allResources) {
                    updateSync("config", group, policy);
                }
                if (featuresSync || allResources) {
                    updateSync("feature", group, policy);
                }
                if (obrSync || allResources) {
                    updateSync("obr.urls", group, policy);
                }
            }
        }
        return null;
    }