Search in sources :

Example 1 with CreateContainerBasicOptions

use of io.fabric8.api.CreateContainerBasicOptions in project fabric8 by jboss-fuse.

the class ContainerBuilder method buildInternal.

private Set<ContainerProxy> buildInternal(Collection<B> buildersList) {
    Set<ContainerProxy> containers = new HashSet<ContainerProxy>();
    BundleContext bundleContext = getBundleContext();
    ServiceLocator.awaitService(getBundleContext(), FabricComplete.class);
    synchronizeGitRepositories();
    FabricService fabricService = fabricServiceServiceProxy.getService();
    CompletionService<Set<ContainerProxy>> completionService = new ExecutorCompletionService<Set<ContainerProxy>>(executorService);
    int tasks = 0;
    for (B builder : buildersList) {
        builder.profiles(profileNames);
        if (!builder.isEnsembleServer()) {
            builder.zookeeperUrl(fabricService.getZookeeperUrl());
            CreateContainerBasicOptions options = builder.build();
            ServiceLocator.awaitService(bundleContext, ContainerProvider.class, "(fabric.container.protocol=" + options.getProviderType() + ")", CREATE_TIMEOUT, TimeUnit.MILLISECONDS);
            completionService.submit(new CreateContainerTask(fabricServiceServiceProxy, options));
            tasks++;
        }
    }
    try {
        for (int i = 0; i < tasks; i++) {
            Future<Set<ContainerProxy>> futureContainerSet = completionService.poll(CREATE_TIMEOUT, TimeUnit.MILLISECONDS);
            Set<ContainerProxy> containerSet = futureContainerSet.get();
            containers.addAll(containerSet);
        }
        try {
            if (waitForProvisioning) {
                Provision.containerStatus(containers, provisionTimeOut);
            }
            if (assertProvisioningResult) {
                Provision.provisioningSuccess(containers, provisionTimeOut, ContainerCallback.DISPLAY_ALL);
            }
        } catch (Exception e) {
            throw FabricException.launderThrowable(e);
        }
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    }
    return Collections.unmodifiableSet(containers);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) FabricException(io.fabric8.api.FabricException) FabricService(io.fabric8.api.FabricService) CreateContainerBasicOptions(io.fabric8.api.CreateContainerBasicOptions) HashSet(java.util.HashSet) BundleContext(org.osgi.framework.BundleContext)

Aggregations

CreateContainerBasicOptions (io.fabric8.api.CreateContainerBasicOptions)1 FabricException (io.fabric8.api.FabricException)1 FabricService (io.fabric8.api.FabricService)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 BundleContext (org.osgi.framework.BundleContext)1