Search in sources :

Example 1 with OpenShiftConfig

use of io.fabric8.openshift.client.OpenShiftConfig in project fabric8 by jboss-fuse.

the class OpenshiftContainerProvider method create.

@Override
public CreateOpenshiftContainerMetadata create(CreateOpenshiftContainerOptions options, CreationStateListener listener) throws Exception {
    assertValid();
    IUser user = getOrCreateConnection(options).getUser();
    IDomain domain = getOrCreateDomain(user, options);
    String cartridgeUrl = null;
    Set<String> profiles = options.getProfiles();
    String versionId = options.getVersion();
    Map<String, String> openshiftConfigOverlay = new HashMap<String, String>();
    if (profiles != null && versionId != null) {
        ProfileService profileService = fabricService.get().adapt(ProfileService.class);
        Version version = profileService.getVersion(versionId);
        if (version != null) {
            for (String profileId : profiles) {
                Profile profile = version.getRequiredProfile(profileId);
                if (profile != null) {
                    Profile overlay = profileService.getOverlayProfile(profile);
                    Map<String, String> openshiftConfig = overlay.getConfiguration(OpenShiftConstants.OPENSHIFT_PID);
                    if (openshiftConfig != null) {
                        openshiftConfigOverlay.putAll(openshiftConfig);
                    }
                }
            }
        }
        cartridgeUrl = openshiftConfigOverlay.get("cartridge");
    }
    if (cartridgeUrl == null) {
        cartridgeUrl = defaultCartridgeUrl;
    }
    String[] cartridgeUrls = cartridgeUrl.split(" ");
    LOG.info("Creating cartridges: " + cartridgeUrl);
    String standAloneCartridgeUrl = cartridgeUrls[0];
    StandaloneCartridge cartridge;
    if (standAloneCartridgeUrl.startsWith(PREFIX_CARTRIDGE_ID)) {
        cartridge = new StandaloneCartridge(standAloneCartridgeUrl.substring(PREFIX_CARTRIDGE_ID.length()));
    } else {
        cartridge = new StandaloneCartridge(new URL(standAloneCartridgeUrl));
    }
    String zookeeperUrl = fabricService.get().getZookeeperUrl();
    String zookeeperPassword = fabricService.get().getZookeeperPassword();
    Map<String, String> userEnvVars = null;
    if (!options.isEnsembleServer()) {
        userEnvVars = new HashMap<String, String>();
        userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_URL", zookeeperUrl);
        userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD", zookeeperPassword);
        String zkPasswordEncode = System.getProperty("zookeeper.password.encode", "true");
        userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD_ENCODE", zkPasswordEncode);
        userEnvVars.put("OPENSHIFT_FUSE_CREATED_FROM_FABRIC", "true");
    }
    String initGitUrl = null;
    int timeout = IHttpClient.NO_TIMEOUT;
    ApplicationScale scale = null;
    String containerName = options.getName();
    long t0 = System.currentTimeMillis();
    IApplication application;
    try {
        application = domain.createApplication(containerName, cartridge, scale, new GearProfile(options.getGearProfile()), initGitUrl, timeout, userEnvVars);
    } catch (OpenShiftTimeoutException e) {
        long t1;
        do {
            Thread.sleep(5000);
            domain.refresh();
            application = domain.getApplicationByName(containerName);
            if (application != null) {
                break;
            }
            t1 = System.currentTimeMillis();
        } while (t1 - t0 < TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES));
    }
    LOG.info("Created application " + containerName);
    // now lets add all the embedded cartridges
    List<IEmbeddableCartridge> list = new ArrayList<IEmbeddableCartridge>();
    for (int idx = 1, size = cartridgeUrls.length; idx < size; idx++) {
        String embeddedUrl = cartridgeUrls[idx];
        LOG.info("Adding embedded cartridge: " + embeddedUrl);
        if (embeddedUrl.startsWith(PREFIX_CARTRIDGE_ID)) {
            list.add(new EmbeddableCartridge(embeddedUrl.substring(PREFIX_CARTRIDGE_ID.length())));
        } else {
            list.add(new EmbeddableCartridge(new URL(embeddedUrl)));
        }
    }
    if (!list.isEmpty()) {
        application.addEmbeddableCartridges(list);
    }
    String gitUrl = application.getGitUrl();
    // in case of OpenShiftTimeoutException, application resource doesn't contain getCreationLog().
    // actually this method throws NPE
    CreateOpenshiftContainerMetadata metadata = new CreateOpenshiftContainerMetadata(domain.getId(), application.getUUID(), application.getMessages() == null ? "" : application.getCreationLog(), gitUrl);
    metadata.setContainerName(containerName);
    metadata.setCreateOptions(options);
    return metadata;
}
Also used : HashMap(java.util.HashMap) ApplicationScale(com.openshift.client.ApplicationScale) OpenShiftTimeoutException(com.openshift.client.OpenShiftTimeoutException) ArrayList(java.util.ArrayList) GearProfile(com.openshift.internal.client.GearProfile) Profile(io.fabric8.api.Profile) IGearProfile(com.openshift.client.IGearProfile) URL(java.net.URL) IDomain(com.openshift.client.IDomain) IApplication(com.openshift.client.IApplication) ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) GearProfile(com.openshift.internal.client.GearProfile) IGearProfile(com.openshift.client.IGearProfile) IUser(com.openshift.client.IUser) EmbeddableCartridge(com.openshift.client.cartridge.EmbeddableCartridge) IEmbeddableCartridge(com.openshift.client.cartridge.IEmbeddableCartridge) StandaloneCartridge(com.openshift.client.cartridge.StandaloneCartridge) IEmbeddableCartridge(com.openshift.client.cartridge.IEmbeddableCartridge)

Example 2 with OpenShiftConfig

use of io.fabric8.openshift.client.OpenShiftConfig in project kie-wb-common by kiegroup.

the class OpenShiftAccessInterfaceImpl method newOpenShiftClient.

@Override
public OpenShiftClient newOpenShiftClient(final ProviderConfig providerConfig) {
    checkInstanceOf("providerConfig", providerConfig, OpenShiftProviderConfig.class);
    OpenShiftConfig clientConfig = buildOpenShiftConfig((OpenShiftProviderConfig) providerConfig);
    return new OpenShiftClient(new DefaultOpenShiftClient(clientConfig));
}
Also used : OpenShiftClient(org.guvnor.ala.openshift.access.OpenShiftClient) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftConfig(io.fabric8.openshift.client.OpenShiftConfig) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient)

Example 3 with OpenShiftConfig

use of io.fabric8.openshift.client.OpenShiftConfig 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(null)));
    /*
         * 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 kubernetesMain = trimToNull(config.getKubernetesMain());
    if (kubernetesMain != null) {
        builder = builder.withMasterUrl(kubernetesMain);
    }
    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 4 with OpenShiftConfig

use of io.fabric8.openshift.client.OpenShiftConfig in project kie-wb-common by kiegroup.

the class OpenShiftAccessTest method testProviderConfig.

@Test
public void testProviderConfig() {
    OpenShiftProviderConfigImpl providerConfig = new OpenShiftProviderConfigImpl().clear();
    providerConfig.setKubernetesMain("https://localhost:8443");
    providerConfig.setKubernetesOapiVersion("v2");
    OpenShiftConfig clientConfig = OpenShiftAccessInterfaceImpl.buildOpenShiftConfig(providerConfig);
    assertEquals("https://localhost:8443/", clientConfig.getMasterUrl());
    assertEquals("https://localhost:8443/oapi/v2/", clientConfig.getOpenShiftUrl());
}
Also used : OpenShiftConfig(io.fabric8.openshift.client.OpenShiftConfig) OpenShiftProviderConfigImpl(org.guvnor.ala.openshift.config.impl.OpenShiftProviderConfigImpl) Test(org.junit.Test)

Aggregations

OpenShiftConfig (io.fabric8.openshift.client.OpenShiftConfig)2 ApplicationScale (com.openshift.client.ApplicationScale)1 IApplication (com.openshift.client.IApplication)1 IDomain (com.openshift.client.IDomain)1 IGearProfile (com.openshift.client.IGearProfile)1 IUser (com.openshift.client.IUser)1 OpenShiftTimeoutException (com.openshift.client.OpenShiftTimeoutException)1 EmbeddableCartridge (com.openshift.client.cartridge.EmbeddableCartridge)1 IEmbeddableCartridge (com.openshift.client.cartridge.IEmbeddableCartridge)1 StandaloneCartridge (com.openshift.client.cartridge.StandaloneCartridge)1 GearProfile (com.openshift.internal.client.GearProfile)1 Profile (io.fabric8.api.Profile)1 ProfileService (io.fabric8.api.ProfileService)1 Version (io.fabric8.api.Version)1 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)1 OpenShiftConfigBuilder (io.fabric8.openshift.client.OpenShiftConfigBuilder)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TlsVersion (okhttp3.TlsVersion)1