Search in sources :

Example 6 with Configuration

use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.

the class RegistryService method pullImageWithPolicy.

/**
 * Check an image, and, if <code>autoPull</code> is set to true, fetch it. Otherwise if the image
 * is not existent, throw an error
 * @param registryConfig registry configuration
 *
 * @throws DockerAccessException
 * @throws MojoExecutionException
 */
public void pullImageWithPolicy(String image, ImagePullManager pullManager, RegistryConfig registryConfig, boolean hasImage) throws DockerAccessException, MojoExecutionException {
    // Already pulled, so we don't need to take care
    if (pullManager.hasAlreadyPulled(image)) {
        return;
    }
    // Check if a pull is required
    if (!imageRequiresPull(hasImage, pullManager.getImagePullPolicy(), image)) {
        return;
    }
    ImageName imageName = new ImageName(image);
    long time = System.currentTimeMillis();
    String actualRegistry = EnvUtil.fistRegistryOf(imageName.getRegistry(), registryConfig.getRegistry());
    docker.pullImage(imageName.getFullName(), createAuthConfig(false, null, actualRegistry, registryConfig), actualRegistry);
    log.info("Pulled %s in %s", imageName.getFullName(), EnvUtil.formatDurationTill(time));
    pullManager.pulled(image);
    if (actualRegistry != null && !imageName.hasRegistry()) {
        // If coming from a registry which was not contained in the original name, add a tag from the
        // full name with the registry to the short name with no-registry.
        docker.tag(imageName.getFullName(actualRegistry), image, false);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName)

Example 7 with Configuration

use of io.fabric8.maven.core.model.Configuration in project docker-maven-plugin by fabric8io.

the class BuildMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
    if (skipBuild) {
        return;
    }
    List<ImageConfiguration> resolvedImages = getResolvedImages();
    if (resolvedImages.isEmpty()) {
        // No Configuration found, so build one up dynamically.
        if (imageName == null) {
            /*
                 * Image name defaults to:
                 *     `${project.groupId}/${project.artifactId}:${project.version}`
                 */
            imageName = project.getGroupId() + "/" + project.getArtifactId() + ":" + project.getVersion();
        }
        ImageConfiguration aDefaultImageConfig = ImageConfiguration.getDefaultImageConfiguration(imageName, project.getBasedir().getAbsolutePath());
        processImageConfig(hub, aDefaultImageConfig);
        return;
    } else {
        // Iterate over all the ImageConfigurations and process one by one
        for (ImageConfiguration imageConfig : resolvedImages) {
            processImageConfig(hub, imageConfig);
        }
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration)

Example 8 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class JoinAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (nonManaged) {
        profile = "unmanaged";
    }
    String oldName = runtimeProperties.getRuntimeIdentity();
    if (System.getenv("OPENSHIFT_BROKER_HOST") != null && containerName != null) {
        System.err.println("Containers in OpenShift cannot be renamed");
        return null;
    }
    if (containerName == null) {
        containerName = oldName;
    }
    FabricValidations.validateContainerName(containerName);
    Configuration bootConfiguration = configAdmin.getConfiguration(BootstrapConfiguration.COMPONENT_PID, null);
    Configuration dataStoreConfiguration = configAdmin.getConfiguration(Constants.DATASTORE_PID, null);
    Configuration configZook = configAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
    if (configZook.getProperties() != null && configZook.getProperties().get("zookeeper.url") != null) {
        System.err.println("This container is already connected to a fabric");
        return null;
    }
    Dictionary<String, Object> bootProperties = bootConfiguration.getProperties();
    if (bootProperties == null) {
        bootProperties = new Hashtable<>();
    }
    if (resolver != null) {
        bootProperties.put(ZkDefs.LOCAL_RESOLVER_PROPERTY, resolver);
    }
    if (manualIp != null) {
        bootProperties.put(ZkDefs.MANUAL_IP, manualIp);
    }
    if (bindAddress != null) {
        bootProperties.put(ZkDefs.BIND_ADDRESS, bindAddress);
    }
    zookeeperPassword = zookeeperPassword != null ? zookeeperPassword : ShellUtils.retrieveFabricZookeeperPassword(session);
    if (zookeeperPassword == null) {
        zookeeperPassword = promptForZookeeperPassword();
    }
    if (zookeeperPassword == null || zookeeperPassword.isEmpty()) {
        System.out.println("No password specified. Cannot join fabric ensemble.");
        return null;
    }
    ShellUtils.storeZookeeperPassword(session, zookeeperPassword);
    log.debug("Encoding ZooKeeper password.");
    String encodedPassword = PasswordEncoder.encode(zookeeperPassword);
    bootProperties.put(ZkDefs.MINIMUM_PORT, String.valueOf(minimumPort));
    bootProperties.put(ZkDefs.MAXIMUM_PORT, String.valueOf(maximumPort));
    Hashtable<String, Object> dataStoreProperties = new Hashtable<String, Object>();
    Configuration cfg = configAdmin.getConfiguration(Constants.DATASTORE_PID, null);
    Dictionary<String, Object> props = cfg.getProperties();
    if (props != null) {
        for (Enumeration<String> keys = cfg.getProperties().keys(); keys.hasMoreElements(); ) {
            String k = keys.nextElement();
            dataStoreProperties.put(k, cfg.getProperties().get(k));
        }
    }
    augmentDataStoreProperties(zookeeperPassword, dataStoreProperties);
    if (!containerName.equals(oldName)) {
        if (force || permissionToRenameContainer()) {
            if (!registerContainer(containerName, zookeeperPassword, profile, force)) {
                System.err.println("A container with the name: " + containerName + " is already member of the cluster. You can specify a different name as an argument.");
                return null;
            }
            bootProperties.put(SystemProperties.KARAF_NAME, containerName);
            // Ensure that if we bootstrap CuratorFramework via RuntimeProperties password is set before the URL.
            bootProperties.put("zookeeper.password", encodedPassword);
            bootProperties.put("zookeeper.url", zookeeperUrl);
            // Rename the container
            Path propsPath = runtimeProperties.getConfPath().resolve("system.properties");
            Properties systemProps = new Properties(propsPath.toFile());
            systemProps.put(SystemProperties.KARAF_NAME, containerName);
            // Also pass zookeeper information so that the container can auto-join after the restart.
            systemProps.put("zookeeper.url", zookeeperUrl);
            systemProps.put("zookeeper.password", encodedPassword);
            systemProps.save();
            System.setProperty("runtime.id", containerName);
            System.setProperty(SystemProperties.KARAF_NAME, containerName);
            System.setProperty("karaf.restart", "true");
            System.setProperty("karaf.restart.clean", "false");
            if (!nonManaged) {
                installBundles();
            }
            // it's only a(n almost certain) way of synchronizing CM and ManagedService.update()
            if (!OsgiUtils.updateCmConfigurationAndWait(bundleContext, bootConfiguration, bootProperties, 10, TimeUnit.SECONDS)) {
                log.warn("Timeout waiting for update of PID: {}", BootstrapConfiguration.COMPONENT_PID);
            }
            if (!OsgiUtils.updateCmConfigurationAndWait(bundleContext, dataStoreConfiguration, dataStoreProperties, 10, TimeUnit.SECONDS)) {
                log.warn("Timeout waiting for update of PID: {}", Constants.DATASTORE_PID);
            }
            // we don't want fileinstall to trigger ConfigAdmin update
            Bundle fileinstall = new BundleUtils(bundleContext).findBundle("org.apache.felix.fileinstall");
            if (fileinstall != null) {
                fileinstall.stop(Bundle.STOP_TRANSIENT);
            }
            persistConfiguration(configAdmin, Constants.DATASTORE_PID, dataStoreProperties);
            // Restart the container
            bundleContext.getBundle(0).stop();
            return null;
        } else {
            return null;
        }
    } else {
        bootConfiguration.update(bootProperties);
        dataStoreConfiguration.update(dataStoreProperties);
        persistConfiguration(configAdmin, Constants.DATASTORE_PID, dataStoreProperties);
        if (!registerContainer(containerName, zookeeperPassword, profile, force)) {
            System.err.println("A container with the name: " + containerName + " is already member of the cluster. You can specify a different name as an argument.");
            return null;
        }
        Configuration config = configAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
        Hashtable<String, Object> properties = new Hashtable<String, Object>();
        properties.put("zookeeper.url", zookeeperUrl);
        properties.put("zookeeper.password", PasswordEncoder.encode(encodedPassword));
        config.setBundleLocation(null);
        config.update(properties);
        if (!nonManaged) {
            installBundles();
        }
        return null;
    }
}
Also used : ZkPath(io.fabric8.zookeeper.ZkPath) Path(java.nio.file.Path) Configuration(org.osgi.service.cm.Configuration) BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) Hashtable(java.util.Hashtable) Bundle(org.osgi.framework.Bundle) SystemProperties(io.fabric8.api.SystemProperties) RuntimeProperties(io.fabric8.api.RuntimeProperties) Properties(org.apache.felix.utils.properties.Properties) BundleUtils(io.fabric8.utils.BundleUtils)

Example 9 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class ProjectDeployerTest method setUp.

@Before
public void setUp() throws Exception {
    URL.setURLStreamHandlerFactory(new CustomBundleURLStreamHandlerFactory());
    basedir = System.getProperty("basedir", ".");
    String karafRoot = basedir + "/target/karaf";
    System.setProperty("karaf.root", karafRoot);
    System.setProperty("karaf.data", karafRoot + "/data");
    sfb = new ZKServerFactoryBean();
    delete(sfb.getDataDir());
    delete(sfb.getDataLogDir());
    sfb.setPort(9123);
    sfb.afterPropertiesSet();
    int zkPort = sfb.getClientPortAddress().getPort();
    LOG.info("Connecting to ZK on port: " + zkPort);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
    curator = builder.build();
    curator.start();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    // setup a local and remote git repo
    File root = new File(basedir + "/target/git").getCanonicalFile();
    delete(root);
    new File(root, "remote").mkdirs();
    remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
    remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
    new File(root, "local").mkdirs();
    git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
    git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", remoteUrl);
    config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    config.save();
    runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
    EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
    EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
    EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
    EasyMock.expect(runtimeProperties.getProperty(EasyMock.eq(SystemProperties.FABRIC_ENVIRONMENT))).andReturn("").anyTimes();
    EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
    EasyMock.replay(runtimeProperties);
    FabricGitServiceImpl gitService = new FabricGitServiceImpl();
    gitService.bindRuntimeProperties(runtimeProperties);
    gitService.activate();
    gitService.setGitForTesting(git);
    /*
        dataStore = new GitDataStoreImpl();
        dataStore.bindCurator(curator);
        dataStore.bindGitService(gitService);
        dataStore.bindRuntimeProperties(runtimeProperties);
        dataStore.bindConfigurer(new Configurer() {
        

            @Override
            public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
                return null;
            }

            @Override
            public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
                return null;
            }
        });
        Map<String, Object> datastoreProperties = new HashMap<String, Object>();
        datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl);
        dataStore.activate(datastoreProperties);
        */
    fabricService = new FabricServiceImpl();
    // fabricService.bindDataStore(dataStore);
    fabricService.bindRuntimeProperties(runtimeProperties);
    fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("port"));
    fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("zk"));
    fabricService.bindPlaceholderResolver(new ProfilePropertyPointerResolver());
    fabricService.bindPlaceholderResolver(new ChecksumPlaceholderResolver());
    fabricService.bindPlaceholderResolver(new VersionPropertyPointerResolver());
    fabricService.bindPlaceholderResolver(new EnvPlaceholderResolver());
    fabricService.activateComponent();
    projectDeployer = new ProjectDeployerImpl();
    projectDeployer.bindFabricService(fabricService);
    projectDeployer.bindMBeanServer(ManagementFactory.getPlatformMBeanServer());
    // dataStore.getDefaultVersion();
    String defaultVersion = null;
    assertEquals("defaultVersion", "1.0", defaultVersion);
    // now lets import some data - using the old non-git file layout...
    String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric/import";
    assertFolderExists(importPath);
    dataStore.importFromFileSystem(importPath);
    assertHasVersion(defaultVersion);
}
Also used : ProfilePropertyPointerResolver(io.fabric8.service.ProfilePropertyPointerResolver) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) FabricGitServiceImpl(io.fabric8.git.internal.FabricGitServiceImpl) ZKServerFactoryBean(io.fabric8.zookeeper.spring.ZKServerFactoryBean) VersionPropertyPointerResolver(io.fabric8.service.VersionPropertyPointerResolver) EnvPlaceholderResolver(io.fabric8.service.EnvPlaceholderResolver) FabricServiceImpl(io.fabric8.service.FabricServiceImpl) StoredConfig(org.eclipse.jgit.lib.StoredConfig) DataStoreTemplate(io.fabric8.api.DataStoreTemplate) ChecksumPlaceholderResolver(io.fabric8.service.ChecksumPlaceholderResolver) File(java.io.File) RuntimeProperties(io.fabric8.api.RuntimeProperties) Before(org.junit.Before)

Example 10 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class ManagedCartridgeConfig method loadConfig.

/**
 * Loads the managed cartridge configuration for the given containerId
 */
public static ManagedCartridgeConfig loadConfig(FabricService fabricService, String containerId) throws IOException {
    String propertiesText = fabricService.adapt(DataStore.class).getContainerAttribute(containerId, DataStore.ContainerAttribute.OpenShift, "", false, substitutedStringValue);
    if (propertiesText == null) {
        return null;
    }
    Properties properties = new Properties();
    properties.load(new StringReader(propertiesText));
    ManagedCartridgeConfig answer = new ManagedCartridgeConfig(properties);
    LOG.info("Loaded managed cartridge configuration " + answer);
    return answer;
}
Also used : DataStore(io.fabric8.api.DataStore) StringReader(java.io.StringReader) Properties(java.util.Properties)

Aggregations

ParallelTest (io.strimzi.test.annotations.ParallelTest)142 Kafka (io.strimzi.api.kafka.model.Kafka)138 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)132 HashMap (java.util.HashMap)97 IOException (java.io.IOException)86 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)83 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)80 Map (java.util.Map)79 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)76 ArrayList (java.util.ArrayList)76 List (java.util.List)70 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)66 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)66 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Service (io.fabric8.kubernetes.api.model.Service)55 Collectors (java.util.stream.Collectors)55 Container (io.fabric8.kubernetes.api.model.Container)54 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)50 Quantity (io.fabric8.kubernetes.api.model.Quantity)48 File (java.io.File)47