Search in sources :

Example 11 with Path

use of io.fabric8.annotations.Path in project docker-maven-plugin by fabric8io.

the class VolumeBindingUtilTest method testResolveRelativeVolumePath.

/**
 * Insures that a host volume binding string that contains a path relative to the current working directory is
 * resolved to the supplied base directory.
 */
@Test
public void testResolveRelativeVolumePath() {
    String volumeString = format(BIND_STRING_FMT, RELATIVE_PATH, CONTAINER_PATH);
    // './rel:/path/to/container/dir' to '/absolute/basedir/rel:/path/to/container/dir'
    String relativizedVolumeString = resolveRelativeVolumeBinding(ABS_BASEDIR, volumeString);
    String expectedBindingString = format(BIND_STRING_FMT, new File(ABS_BASEDIR, stripLeadingPeriod(RELATIVE_PATH)), CONTAINER_PATH);
    assertEquals(expectedBindingString, relativizedVolumeString);
}
Also used : PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) Test(org.junit.Test)

Example 12 with Path

use of io.fabric8.annotations.Path in project docker-maven-plugin by fabric8io.

the class VolumeBindingUtilTest method testResolveRelativeVolumePathWithAccessSpecifications.

/**
 * Insures that a host volume binding string that contains a path relative to the current working directory <em>and
 * </em> specifies access controls resolves to the supplied base directory <em>and</em> that the access controls are
 * preserved through the operation.
 */
@Test
public void testResolveRelativeVolumePathWithAccessSpecifications() {
    String volumeString = format(BIND_STRING_WITH_ACCESS_FMT, RELATIVE_PATH, CONTAINER_PATH, RO_ACCESS);
    // './rel:/path/to/container/dir:ro' to '/absolute/basedir/rel:/path/to/container/dir:ro'
    String relativizedVolumeString = resolveRelativeVolumeBinding(ABS_BASEDIR, volumeString);
    String expectedBindingString = format(BIND_STRING_WITH_ACCESS_FMT, new File(ABS_BASEDIR, stripLeadingPeriod(RELATIVE_PATH)), CONTAINER_PATH, RO_ACCESS);
    assertEquals(expectedBindingString, relativizedVolumeString);
}
Also used : PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) Test(org.junit.Test)

Example 13 with Path

use of io.fabric8.annotations.Path in project kie-wb-common by kiegroup.

the class OpenShiftAccessInterfaceImpl method buildOpenShiftConfig.

// package-protected for junit testing purposes (from inside the package)
static OpenShiftConfig buildOpenShiftConfig(OpenShiftProviderConfig config) {
    OpenShiftConfigBuilder builder = new OpenShiftConfigBuilder(OpenShiftConfig.wrap(Config.autoConfigure()));
    /*
         * Kubernetes configuration properties; see io.fabric8.kubernetes.client.Config
         */
    String allProxy = trimToNull(config.getAllProxy());
    if (allProxy != null) {
        builder = builder.withHttpProxy(allProxy);
        builder = builder.withHttpsProxy(allProxy);
    }
    String httpProxy = trimToNull(config.getHttpProxy());
    if (httpProxy != null) {
        // NOTE: overrides allProxy above
        builder = builder.withHttpProxy(httpProxy);
    }
    String httpsProxy = trimToNull(config.getHttpsProxy());
    if (httpsProxy != null) {
        // NOTE: overrides allProxy above
        builder = builder.withHttpsProxy(httpsProxy);
    }
    String kubernetesApiVersion = trimToNull(config.getKubernetesApiVersion());
    if (kubernetesApiVersion != null) {
        builder = builder.withApiVersion(kubernetesApiVersion);
    }
    String kubernetesAuthBasicPassword = trimToNull(config.getKubernetesAuthBasicPassword());
    if (kubernetesAuthBasicPassword != null) {
        builder = builder.withPassword(kubernetesAuthBasicPassword);
    }
    String kubernetesAuthBasicUsername = trimToNull(config.getKubernetesAuthBasicUsername());
    if (kubernetesAuthBasicUsername != null) {
        builder = builder.withUsername(kubernetesAuthBasicUsername);
    }
    String kubernetesAuthToken = trimToNull(config.getKubernetesAuthToken());
    if (kubernetesAuthToken != null) {
        builder = builder.withOauthToken(kubernetesAuthToken);
    }
    String kubernetesCertsCaData = trimToNull(config.getKubernetesCertsCaData());
    if (kubernetesCertsCaData != null) {
        builder = builder.withCaCertData(kubernetesCertsCaData);
    }
    String kubernetesCertsCaFile = trimToNull(config.getKubernetesCertsCaFile());
    if (kubernetesCertsCaFile != null) {
        builder = builder.withCaCertFile(kubernetesCertsCaFile);
    }
    String kubernetesCertsClientData = trimToNull(config.getKubernetesCertsClientData());
    if (kubernetesCertsClientData != null) {
        builder = builder.withClientCertData(kubernetesCertsClientData);
    }
    String kubernetesCertsClientFile = trimToNull(config.getKubernetesCertsClientFile());
    if (kubernetesCertsClientFile != null) {
        builder = builder.withClientCertFile(kubernetesCertsClientFile);
    }
    String kubernetesCertsClientKeyAlgo = trimToNull(config.getKubernetesCertsClientKeyAlgo());
    if (kubernetesCertsClientKeyAlgo != null) {
        builder = builder.withClientKeyAlgo(kubernetesCertsClientKeyAlgo);
    }
    String kubernetesCertsClientKeyData = trimToNull(config.getKubernetesCertsClientKeyData());
    if (kubernetesCertsClientKeyData != null) {
        builder = builder.withClientKeyData(kubernetesCertsClientKeyData);
    }
    String kubernetesCertsClientKeyFile = trimToNull(config.getKubernetesCertsClientKeyFile());
    if (kubernetesCertsClientKeyFile != null) {
        builder = builder.withClientKeyFile(kubernetesCertsClientKeyFile);
    }
    String kubernetesCertsClientKeyPassphrase = trimToNull(config.getKubernetesCertsClientKeyPassphrase());
    if (kubernetesCertsClientKeyPassphrase != null) {
        builder = builder.withClientKeyPassphrase(kubernetesCertsClientKeyPassphrase);
    }
    String kubernetesConnectionTimeout = trimToNull(config.getKubernetesConnectionTimeout());
    if (kubernetesConnectionTimeout != null) {
        builder = builder.withConnectionTimeout(Integer.parseInt(kubernetesConnectionTimeout));
    }
    String kubernetesKeystoreFile = trimToNull(config.getKubernetesKeystoreFile());
    if (kubernetesKeystoreFile != null) {
        builder = builder.withKeyStoreFile(kubernetesKeystoreFile);
    }
    String kubernetesKeystorePassphrase = trimToNull(config.getKubernetesKeystorePassphrase());
    if (kubernetesKeystorePassphrase != null) {
        builder = builder.withKeyStorePassphrase(kubernetesKeystorePassphrase);
    }
    String kubernetesLoggingInterval = trimToNull(config.getKubernetesLoggingInterval());
    if (kubernetesLoggingInterval != null) {
        builder = builder.withLoggingInterval(Integer.parseInt(kubernetesLoggingInterval));
    }
    String kubernetesMaster = trimToNull(config.getKubernetesMaster());
    if (kubernetesMaster != null) {
        builder = builder.withMasterUrl(kubernetesMaster);
    }
    String kubernetesNamespace = trimToNull(config.getKubernetesNamespace());
    if (kubernetesNamespace != null) {
        builder = builder.withNamespace(kubernetesNamespace);
    }
    String kubernetesRequestTimeout = trimToNull(config.getKubernetesRequestTimeout());
    if (kubernetesRequestTimeout != null) {
        builder = builder.withRequestTimeout(Integer.parseInt(kubernetesRequestTimeout));
    }
    String kubernetesRollingTimeout = trimToNull(config.getKubernetesRollingTimeout());
    if (kubernetesRollingTimeout != null) {
        builder = builder.withRollingTimeout(Long.parseLong(kubernetesRollingTimeout));
    }
    String kubernetesScaleTimeout = trimToNull(config.getKubernetesScaleTimeout());
    if (kubernetesScaleTimeout != null) {
        builder = builder.withScaleTimeout(Long.parseLong(kubernetesScaleTimeout));
    }
    String kubernetesTlsVersions = trimToNull(config.getKubernetesTlsVersions());
    if (kubernetesTlsVersions != null) {
        String[] split = kubernetesTlsVersions.split(",");
        TlsVersion[] vers = new TlsVersion[split.length];
        for (int i = 0; i < split.length; i++) {
            vers[i] = TlsVersion.forJavaName(split[i]);
        }
        builder.withTlsVersions(vers);
    }
    String kubernetesTrustCertificates = trimToNull(config.getKubernetesTrustCertificates());
    if (kubernetesTrustCertificates != null) {
        builder = builder.withTrustCerts(Boolean.parseBoolean(kubernetesTrustCertificates));
    }
    String kubernetesTruststoreFile = trimToNull(config.getKubernetesTruststoreFile());
    if (kubernetesTruststoreFile != null) {
        builder = builder.withTrustStoreFile(kubernetesTruststoreFile);
    }
    String kubernetesTruststorePassphrase = trimToNull(config.getKubernetesTruststorePassphrase());
    if (kubernetesTruststorePassphrase != null) {
        builder = builder.withTrustStorePassphrase(kubernetesTruststorePassphrase);
    }
    String kubernetesUserAgent = trimToNull(config.getKubernetesUserAgent());
    if (kubernetesUserAgent != null) {
        builder = builder.withUserAgent(kubernetesUserAgent);
    }
    String kubernetesWatchReconnectInterval = trimToNull(config.getKubernetesWatchReconnectInterval());
    if (kubernetesWatchReconnectInterval != null) {
        builder = builder.withWatchReconnectInterval(Integer.parseInt(kubernetesWatchReconnectInterval));
    }
    String kubernetesWatchReconnectLimit = trimToNull(config.getKubernetesWatchReconnectLimit());
    if (kubernetesWatchReconnectLimit != null) {
        builder = builder.withWatchReconnectLimit(Integer.parseInt(kubernetesWatchReconnectLimit));
    }
    String kubernetesWebsocketPingInterval = trimToNull(config.getKubernetesWebsocketPingInterval());
    if (kubernetesWebsocketPingInterval != null) {
        builder = builder.withWebsocketPingInterval(Long.parseLong(kubernetesWebsocketPingInterval));
    }
    String kubernetesWebsocketTimeout = trimToNull(config.getKubernetesWebsocketTimeout());
    if (kubernetesWebsocketTimeout != null) {
        builder = builder.withWebsocketTimeout(Long.parseLong(kubernetesWebsocketTimeout));
    }
    String noProxy = trimToNull(config.getNoProxy());
    if (noProxy != null) {
        builder = builder.withNoProxy(noProxy.split(","));
    }
    String proxyPassword = trimToNull(config.getProxyPassword());
    if (proxyPassword != null) {
        builder = builder.withProxyPassword(proxyPassword);
    }
    String proxyUsername = trimToNull(config.getProxyUsername());
    if (proxyUsername != null) {
        builder = builder.withProxyUsername(proxyUsername);
    }
    /*
         * OpenShift configuration properties; see io.fabric8.openshift.client.OpenShiftConfig
         */
    String kubernetesOapiVersion = trimToNull(config.getKubernetesOapiVersion());
    if (kubernetesOapiVersion != null) {
        builder = builder.withOapiVersion(kubernetesOapiVersion);
    }
    String openshiftBuildTimeout = trimToNull(config.getOpenshiftBuildTimeout());
    if (openshiftBuildTimeout != null) {
        builder = builder.withBuildTimeout(Long.parseLong(openshiftBuildTimeout));
    }
    String openshiftUrl = trimToNull(config.getOpenshiftUrl());
    if (openshiftUrl != null) {
        // The OPENSHIFT_URL environment variable may be set to the root url (i.e. without the '/oapi/version' path) in some configurations
        if (isRootUrl(openshiftUrl)) {
            openshiftUrl = URLUtils.join(openshiftUrl, "oapi", builder.getOapiVersion());
        }
        builder = builder.withOpenShiftUrl(openshiftUrl);
    } else {
        builder.withOpenShiftUrl(URLUtils.join(builder.getMasterUrl(), "oapi", builder.getOapiVersion()));
    }
    return builder.build();
}
Also used : TlsVersion(okhttp3.TlsVersion) OpenShiftConfigBuilder(io.fabric8.openshift.client.OpenShiftConfigBuilder)

Example 14 with Path

use of io.fabric8.annotations.Path 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 15 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method setFileConfigurations.

private void setFileConfigurations(GitContext context, final String versionId, final String profileId, final Map<String, byte[]> fileConfigurations) throws IOException, GitAPIException {
    assertWriteLock();
    // Delete and remove stale file configurations
    File profileDir = GitHelpers.getProfileDirectory(getGit(), profileId);
    final HashSet<File> filesToDelete = new HashSet<File>();
    if (profileDir.exists()) {
        final List<File> filesList = new ArrayList<File>();
        java.nio.file.Files.walkFileTree(profileDir.toPath(), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
                if (!Constants.AGENT_PROPERTIES.equals(path.getFileName().toString())) {
                    filesToDelete.add(path.toFile());
                }
                return super.visitFile(path, attrs);
            }
        });
    }
    for (Map.Entry<String, byte[]> entry : fileConfigurations.entrySet()) {
        String fileName = entry.getKey();
        byte[] newCfg = entry.getValue();
        setFileConfiguration(getGit(), profileId, fileName, newCfg);
        filesToDelete.remove(new File(profileDir, fileName));
    }
    for (File file : filesToDelete) {
        recursiveDeleteAndRemove(getGit(), file);
    }
    if (!fileConfigurations.isEmpty() || !filesToDelete.isEmpty()) {
        context.commitMessage("Update configurations for profile: " + profileId);
    }
}
Also used : Path(java.nio.file.Path) ZkPath(io.fabric8.zookeeper.ZkPath) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

Test (org.junit.Test)45 File (java.io.File)41 IOException (java.io.IOException)34 ArrayList (java.util.ArrayList)18 PathTestUtil.createTmpFile (io.fabric8.maven.docker.util.PathTestUtil.createTmpFile)17 HashMap (java.util.HashMap)12 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)11 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)11 Path (java.nio.file.Path)11 FabricService (io.fabric8.api.FabricService)10 RuntimeProperties (io.fabric8.api.RuntimeProperties)9 Properties (java.util.Properties)9 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)8 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)8 InputStream (java.io.InputStream)8 Path (javax.ws.rs.Path)8 HttpProxyRule (io.fabric8.gateway.model.HttpProxyRule)7 NodeState (io.fabric8.groups.NodeState)7 URISyntaxException (java.net.URISyntaxException)7 List (java.util.List)6