Search in sources :

Example 81 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.

the class Subsystem method downloadBundles.

@SuppressWarnings("InfiniteLoopStatement")
public void downloadBundles(DownloadManager manager, MetadataBuilder builder, Set<String> overrides, String featureResolutionRange) throws Exception {
    for (Subsystem child : children) {
        child.downloadBundles(manager, builder, overrides, featureResolutionRange);
    }
    final Map<String, ResourceImpl> bundles = new ConcurrentHashMap<>();
    final Downloader downloader = manager.createDownloader();
    final Map<BundleInfo, Conditional> infos = new HashMap<>();
    if (feature != null) {
        for (Conditional cond : feature.getConditional()) {
            for (final BundleInfo bi : cond.getBundles()) {
                infos.put(bi, cond);
            }
        }
        for (BundleInfo bi : feature.getBundles()) {
            infos.put(bi, null);
        }
    }
    ResourceBuilderCallback callback = new ResourceBuilderCallback(bundles, builder);
    for (Map.Entry<BundleInfo, Conditional> entry : infos.entrySet()) {
        final BundleInfo bi = entry.getKey();
        final String loc = bi.getLocation();
        downloader.download(loc, callback);
    }
    for (Clause bundle : Parser.parseClauses(this.bundles.toArray(new String[this.bundles.size()]))) {
        final String loc = bundle.getName();
        downloader.download(loc, callback);
    }
    for (final FabricBundle fabricBundle : fabricBundles) {
        final String loc = fabricBundle.getLocation();
        downloader.download(loc, callback);
    }
    for (String override : overrides) {
        final String loc = Overrides.extractUrl(override);
        downloader.download(loc, callback);
    }
    downloader.await();
    Overrides.override(bundles, overrides);
    if (feature != null) {
        // Add conditionals
        Map<Conditional, Resource> resConds = new HashMap<>();
        for (Conditional cond : feature.getConditional()) {
            FeatureResource resCond = FeatureResource.build(feature, cond, featureResolutionRange, bundles);
            addIdentityRequirement(this, resCond, false);
            addIdentityRequirement(resCond, this, true);
            installable.add(resCond);
            resConds.put(cond, resCond);
        }
        // Add features
        FeatureResource resFeature = FeatureResource.build(feature, featureResolutionRange, bundles);
        addIdentityRequirement(resFeature, this);
        installable.add(resFeature);
        // Add dependencies
        for (Map.Entry<BundleInfo, Conditional> entry : infos.entrySet()) {
            final BundleInfo bi = entry.getKey();
            final String loc = bi.getLocation();
            final Conditional cond = entry.getValue();
            ResourceImpl res = bundles.get(loc);
            int sl = bi.getStartLevel() <= 0 ? feature.getStartLevel() : bi.getStartLevel();
            if (bi.isDependency()) {
                addDependency(res, false, bi.isStart(), sl);
            } else {
                doAddDependency(res, cond == null, bi.isStart(), sl);
            }
            if (cond != null) {
                addIdentityRequirement(res, resConds.get(cond), true);
            }
        }
    }
    for (Clause bundle : Parser.parseClauses(this.bundles.toArray(new String[this.bundles.size()]))) {
        final String loc = bundle.getName();
        boolean dependency = Boolean.parseBoolean(bundle.getAttribute("dependency"));
        boolean start = bundle.getAttribute("start") == null || Boolean.parseBoolean(bundle.getAttribute("start"));
        int startLevel = 0;
        try {
            startLevel = Integer.parseInt(bundle.getAttribute("start-level"));
        } catch (NumberFormatException e) {
        // Ignore
        }
        if (dependency) {
            addDependency(bundles.get(loc), false, start, startLevel);
        } else {
            doAddDependency(bundles.get(loc), true, start, startLevel);
            addIdentityRequirement(this, bundles.get(loc));
        }
    }
    for (final FabricBundle fabricBundle : fabricBundles) {
        final String loc = fabricBundle.getLocation();
        boolean dependency = Boolean.parseBoolean(fabricBundle.getProperty("dependency"));
        boolean start = fabricBundle.getProperty("start") == null || Boolean.parseBoolean(fabricBundle.getProperty("start"));
        int startLevel = 0;
        try {
            startLevel = Integer.parseInt(fabricBundle.getProperty("start-level"));
        } catch (NumberFormatException e) {
        // Ignore
        }
        if (dependency) {
            addDependency(bundles.get(loc), false, start, startLevel);
        } else {
            doAddDependency(bundles.get(loc), true, start, startLevel);
            addIdentityRequirement(this, bundles.get(loc));
        }
    }
    // Compute dependencies
    for (DependencyInfo info : dependencies.values()) {
        installable.add(info.resource);
        addIdentityRequirement(info.resource, this, info.mandatory);
    }
}
Also used : FeatureResource(io.fabric8.agent.resolver.FeatureResource) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Resource(org.osgi.resource.Resource) FeatureResource(io.fabric8.agent.resolver.FeatureResource) Downloader(io.fabric8.agent.download.Downloader) Conditional(io.fabric8.agent.model.Conditional) ResourceImpl(io.fabric8.agent.resolver.ResourceImpl) BundleInfo(io.fabric8.agent.model.BundleInfo) Clause(org.apache.felix.utils.manifest.Clause) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 82 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.

the class WatcherSpringContext method destroy.

public void destroy() {
    if (closing.compareAndSet(false, true)) {
        Set<Map.Entry<String, FileSystemXmlApplicationContext>> entries = contextMap.entrySet();
        for (Map.Entry<String, FileSystemXmlApplicationContext> entry : entries) {
            String url = entry.getKey();
            FileSystemXmlApplicationContext context = entry.getValue();
            closeContext(url, context);
        }
    }
    super.destroy();
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) PathHelper.toUrlString(io.fabric8.watcher.PathHelper.toUrlString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 83 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.

the class ProfileDisplayAction method displayProfile.

private void displayProfile(Profile profile) {
    PrintStream output = System.out;
    output.println("Profile id: " + profile.getId());
    output.println("Version   : " + profile.getVersion());
    output.println("Attributes: ");
    Map<String, String> props = profile.getAttributes();
    for (String key : props.keySet()) {
        output.println("\t" + key + ": " + props.get(key));
    }
    String versionId = profile.getVersion();
    String profileId = profile.getId();
    output.printf("Containers: %s\n", toString(fabricService.getAssociatedContainers(versionId, profileId)));
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    if (overlay) {
        profile = profileService.getOverlayProfile(profile);
    }
    Map<String, Map<String, String>> configuration = new HashMap<>(profile.getConfigurations());
    Map<String, byte[]> resources = profile.getFileConfigurations();
    Map<String, String> agentConfiguration = profile.getConfiguration(Constants.AGENT_PID);
    List<String> agentProperties = new ArrayList<String>();
    List<String> systemProperties = new ArrayList<String>();
    List<String> configProperties = new ArrayList<String>();
    List<String> otherResources = new ArrayList<String>();
    for (Map.Entry<String, String> entry : agentConfiguration.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (value.contains(",")) {
            value = "\t" + value.replace(",", ",\n\t\t");
        }
        if (key.startsWith("system.")) {
            systemProperties.add("  " + key.substring("system.".length()) + " = " + value);
        } else if (key.startsWith("config.")) {
            configProperties.add("  " + key.substring("config.".length()) + " = " + value);
        } else if (!key.startsWith("feature.") && !key.startsWith("repository") && !key.startsWith("bundle.") && !key.startsWith("fab.") && !key.startsWith("override.") && !key.startsWith("attribute.")) {
            agentProperties.add("  " + key + " = " + value);
        }
    }
    if (configuration.containsKey(Constants.AGENT_PID)) {
        output.println("\nContainer settings");
        output.println("----------------------------");
        if (profile.getLibraries().size() > 0) {
            printConfigList("Libraries : ", output, profile.getLibraries());
        }
        if (profile.getRepositories().size() > 0) {
            printConfigList("Repositories : ", output, profile.getRepositories());
        }
        if (profile.getFeatures().size() > 0) {
            printConfigList("Features : ", output, profile.getFeatures());
        }
        if (profile.getBundles().size() > 0) {
            printConfigList("Bundles : ", output, profile.getBundles());
        }
        if (profile.getFabs().size() > 0) {
            printConfigList("Fabs : ", output, profile.getFabs());
        }
        if (profile.getOverrides().size() > 0) {
            printConfigList("Overrides : ", output, profile.getOverrides());
        }
        if (agentProperties.size() > 0) {
            printConfigList("Agent Properties : ", output, agentProperties);
        }
        if (systemProperties.size() > 0) {
            printConfigList("System Properties : ", output, systemProperties);
        }
        if (configProperties.size() > 0) {
            printConfigList("Config Properties : ", output, configProperties);
        }
        configuration.remove(Constants.AGENT_PID);
    }
    output.println("\nConfiguration details");
    output.println("----------------------------");
    for (Map.Entry<String, Map<String, String>> cfg : configuration.entrySet()) {
        output.println("PID: " + cfg.getKey());
        for (Map.Entry<String, String> values : cfg.getValue().entrySet()) {
            output.println("  " + values.getKey() + " " + values.getValue());
        }
        output.println("\n");
    }
    output.println("\nOther resources");
    output.println("----------------------------");
    for (Map.Entry<String, byte[]> resource : resources.entrySet()) {
        String name = resource.getKey();
        if (!name.endsWith(".properties")) {
            output.println("Resource: " + resource.getKey());
            if (displayResources) {
                output.println(new String(resource.getValue(), Charsets.UTF_8));
                output.println("\n");
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProfileService(io.fabric8.api.ProfileService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 84 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.

the class AbstractExtenderListener method getExtenderStatus.

/**
 * Updates the extender status
 */
protected ModuleStatus getExtenderStatus() {
    int starting = 0;
    int failed = 0;
    int waiting = 0;
    int stopping = 0;
    for (Map.Entry<Long, ModuleStatus> entry : statusMap.entrySet()) {
        ModuleStatus moduleStatus = entry.getValue();
        if (moduleStatus == ModuleStatus.FAILED) {
            failed++;
        } else if (moduleStatus == ModuleStatus.WAITING) {
            waiting++;
        } else if (moduleStatus == ModuleStatus.STOPPING) {
            stopping++;
        } else if (moduleStatus == ModuleStatus.STARTING) {
            starting++;
        }
    }
    if (failed > 0) {
        return ModuleStatus.FAILED;
    } else if (waiting > 0) {
        return ModuleStatus.WAITING;
    } else if (stopping > 0) {
        return ModuleStatus.STOPPING;
    } else if (starting > 0) {
        return ModuleStatus.STARTING;
    } else {
        return ModuleStatus.STARTED;
    }
}
Also used : ModuleStatus(io.fabric8.api.ModuleStatus) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 85 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.

the class GitHttpServerRegistrationHandler method zkCleanUp.

private void zkCleanUp(Group<GitNode> group) {
    try {
        RuntimeProperties sysprops = runtimeProperties.get();
        String runtimeIdentity = sysprops.getRuntimeIdentity();
        curator.get().newNamespaceAwareEnsurePath(ZkPath.GIT.getPath()).ensure(curator.get().getZookeeperClient());
        List<String> allChildren = ZooKeeperUtils.getAllChildren(curator.get(), ZkPath.GIT.getPath());
        for (String path : allChildren) {
            String stringData = ZooKeeperUtils.getStringData(curator.get(), path);
            if (stringData.contains("\"container\":\"" + runtimeIdentity + "\"")) {
                LOGGER.info("Found older ZK \"/fabric/registry/clusters/git\" entry for node " + runtimeIdentity);
                ZooKeeperUtils.delete(curator.get(), path);
                LOGGER.info("Older ZK \"/fabric/registry/clusters/git\" entry for node " + runtimeIdentity + " has been removed");
            }
        }
    } catch (KeeperException.NoNodeException ignored) {
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : RuntimeProperties(io.fabric8.api.RuntimeProperties) KeeperException(org.apache.zookeeper.KeeperException) InstanceNotFoundException(javax.management.InstanceNotFoundException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Aggregations

Map (java.util.Map)89 HashMap (java.util.HashMap)57 IOException (java.io.IOException)31 File (java.io.File)30 ArrayList (java.util.ArrayList)26 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)16 List (java.util.List)14 Properties (java.util.Properties)14 HashSet (java.util.HashSet)10 Entry (io.fabric8.maven.docker.config.CopyConfiguration.Entry)9 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)9 Test (org.junit.Test)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 LinkedHashMap (java.util.LinkedHashMap)8 TreeMap (java.util.TreeMap)8 Resource (io.fabric8.kubernetes.client.dsl.Resource)7 FileInputStream (java.io.FileInputStream)7 Set (java.util.Set)7 Profile (io.fabric8.api.Profile)6 ProfileService (io.fabric8.api.ProfileService)5