Search in sources :

Example 11 with Configuration

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

the class ManagedCartridgeConfig method saveConfig.

/**
 * Saves the managed cartridge configuration data
 */
public static ManagedCartridgeConfig saveConfig(FabricService fabricService, String containerId, CreateOpenshiftContainerOptions options, IApplication application) throws IOException {
    ManagedCartridgeConfig config = new ManagedCartridgeConfig();
    config.setServerUrl(options.getServerUrl());
    config.setLogin(options.getLogin());
    config.setPassword(options.getPassword());
    StringWriter writer = new StringWriter();
    config.getProperties().store(writer, "Saved by " + config.getClass() + " at " + new Date());
    String propertiesText = writer.toString();
    LOG.info("Saved managed cartridge configuration: " + propertiesText);
    fabricService.adapt(DataStore.class).setContainerAttribute(containerId, DataStore.ContainerAttribute.OpenShift, propertiesText);
    return config;
}
Also used : StringWriter(java.io.StringWriter) DataStore(io.fabric8.api.DataStore) Date(java.util.Date)

Example 12 with Configuration

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

the class OpenShiftDeployAgent method onConfigurationChanged.

protected void onConfigurationChanged() {
    LOGGER.info("Configuration has changed; so checking the Fabric managed Java cartridges on OpenShift are up to date");
    Container[] containers = fabricService.get().getContainers();
    for (Container container : containers) {
        Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService.get(), container.getOverlayProfile());
        Map<String, String> openshiftConfiguration = effectiveProfile.getConfiguration(OpenShiftConstants.OPENSHIFT_PID);
        if (openshiftConfiguration != null) {
            DeploymentUpdater deployTask = null;
            try {
                deployTask = createDeployTask(container, openshiftConfiguration);
            } catch (MalformedURLException e) {
                LOGGER.error("Failed to create DeploymentUpdater. " + e, e);
            }
            if (deployTask != null && OpenShiftUtils.isFabricManaged(openshiftConfiguration)) {
                String containerId = container.getId();
                IOpenShiftConnection connection = OpenShiftUtils.createConnection(container);
                CreateOpenshiftContainerOptions options = OpenShiftUtils.getCreateOptions(container);
                if (connection == null || options == null) {
                    LOGGER.warn("Ignoring container which has no openshift connection or options. connection: " + connection + " options: " + options);
                } else {
                    try {
                        IApplication application = OpenShiftUtils.getApplication(container, connection);
                        if (application != null) {
                            final String gitUrl = application.getGitUrl();
                            if (gitUrl != null) {
                                LOGGER.info("Git URL is " + gitUrl);
                                final CartridgeGitRepository repo = new CartridgeGitRepository(containerId);
                                final List<IOpenShiftSSHKey> sshkeys = application.getDomain().getUser().getSSHKeys();
                                final CredentialsProvider credentials = new CredentialsProvider() {

                                    @Override
                                    public boolean supports(CredentialItem... items) {
                                        return true;
                                    }

                                    @Override
                                    public boolean isInteractive() {
                                        return true;
                                    }

                                    @Override
                                    public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
                                        LOGGER.info("Credential request " + uri + " items " + Arrays.asList(items));
                                        int i = -1;
                                        for (CredentialItem item : items) {
                                            if (item instanceof CredentialItem.StringType) {
                                                CredentialItem.StringType stringType = (CredentialItem.StringType) item;
                                                int idx = ++i < sshkeys.size() ? i : 0;
                                                if (idx < sshkeys.size()) {
                                                    IOpenShiftSSHKey sshKey = sshkeys.get(idx);
                                                    String passphrase = sshKey.getPublicKey();
                                                    LOGGER.info("For item " + item + " index " + i + " using passphrase: " + passphrase);
                                                    stringType.setValue(passphrase);
                                                } else {
                                                    LOGGER.warn("No ssh keys we can pass into git!");
                                                }
                                                continue;
                                            } else {
                                                LOGGER.warn("Unknown CredentialItem " + item);
                                            }
                                        }
                                        return true;
                                    }
                                };
                                final DeploymentUpdater finalDeployTask = deployTask;
                                SshSessionFactoryUtils.useOpenShiftSessionFactory(new Callable<Object>() {

                                    @Override
                                    public Object call() throws Exception {
                                        repo.cloneOrPull(gitUrl, credentials);
                                        finalDeployTask.updateDeployment(repo.getGit(), repo.getLocalRepo(), credentials);
                                        return null;
                                    }
                                });
                            }
                        }
                    } catch (Exception e) {
                        LOGGER.error("Failed to update container " + containerId + ". Reason: " + e, e);
                    } finally {
                        OpenShiftUtils.close(connection);
                    }
                }
            }
        }
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) MalformedURLException(java.net.MalformedURLException) CreateOpenshiftContainerOptions(io.fabric8.openshift.CreateOpenshiftContainerOptions) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) IOpenShiftSSHKey(com.openshift.client.IOpenShiftSSHKey) Profile(io.fabric8.api.Profile) MalformedURLException(java.net.MalformedURLException) Container(io.fabric8.api.Container) IApplication(com.openshift.client.IApplication) IOpenShiftConnection(com.openshift.client.IOpenShiftConnection)

Example 13 with Configuration

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

the class OpenShiftDeployAgent method activate.

@Activate
void activate(Map<String, ?> configuration) {
    // this.realm =  properties != null && properties.containsKey(REALM_PROPERTY_NAME) ? properties.get(REALM_PROPERTY_NAME) : DEFAULT_REALM;
    // this.role =  properties != null && properties.containsKey(ROLE_PROPERTY_NAME) ? properties.get(ROLE_PROPERTY_NAME) : DEFAULT_ROLE;
    group = new ZooKeeperGroup(curator.get(), ZkPath.OPENSHIFT.getPath(), ControllerNode.class);
    group.add(this);
    group.update(createState());
    group.start();
    activateComponent();
}
Also used : ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) Activate(org.apache.felix.scr.annotations.Activate)

Example 14 with Configuration

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

the class OpenShiftPomDeployer method updateDependencyPlugin.

/**
 * Lets add/update the maven dependency plugin configuration to copy deployments
 * to the deployDir or the webAppDir
 */
protected void updateDependencyPlugin(Element plugins, Element dependencies, Collection<Parser> artifacts) throws XPathExpressionException {
    Element plugin = getOrCreatePlugin(plugins, "maven-dependency-plugin", "2.8");
    Element executions = getOrCreateChild(plugin, "executions", 6);
    List<Parser> warArtifacts = new ArrayList<Parser>();
    List<Parser> jarArtifacts = new ArrayList<Parser>();
    for (Parser artifact : artifacts) {
        String type = artifact.getType();
        if (Objects.equal("war", type)) {
            warArtifacts.add(artifact);
        } else {
            jarArtifacts.add(artifact);
        }
    }
    if (Strings.isNotBlank(webAppDir) && !warArtifacts.isEmpty()) {
        recreateDependencyExecution(executions, dependencies, "fuse-fabric-deploy-webapps", webAppDir, warArtifacts, true);
    }
    if (Strings.isNotBlank(deployDir) && !jarArtifacts.isEmpty()) {
        recreateDependencyExecution(executions, dependencies, "fuse-fabric-deploy-shared", deployDir, jarArtifacts, false);
    }
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Parser(io.fabric8.maven.util.Parser)

Example 15 with Configuration

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

the class OpenShiftPomDeployer method recreateDependencyExecution.

protected Element recreateDependencyExecution(Element executions, Element dependencies, String executionId, String outputDir, List<Parser> list, boolean isWar) throws XPathExpressionException {
    // lets make sure the output dir is trimmed of "/"
    while (outputDir.startsWith("/")) {
        outputDir = outputDir.substring(1);
    }
    Element execution = recreateChild(executions, "execution[id = '" + executionId + "']", "execution", 7);
    createAndAppendChild(execution, "id", 8, executionId);
    createAndAppendChild(execution, "phase", 8, "package");
    Element goals = createAndAppendChild(execution, "goals", 8);
    createAndAppendChild(goals, "goal", 9, "copy");
    Element configuration = createAndAppendChild(execution, "configuration", 9);
    Element artifactItems = createAndAppendChild(configuration, "artifactItems", 10);
    for (Parser parser : list) {
        Element artifactItem = createAndAppendChild(artifactItems, "artifactItem", 11);
        addMavenCoordinates(artifactItem, parser, 12);
        addOrUpdateDependency(dependencies, parser);
        createAndAppendChild(artifactItem, "overWrite", 12, "true");
        createAndAppendChild(artifactItem, "outputDirectory", 12, "${basedir}/" + outputDir);
        // TODO use ROOT if this is the configured web app!
        if (isWar) {
            createAndAppendChild(artifactItem, "destFileName", 12, parser.getArtifact() + ".war");
        }
    }
    createAndAppendChild(configuration, "outputDirectory", 10, "${basedir}/" + outputDir);
    createAndAppendChild(configuration, "overWriteReleases", 10, "true");
    createAndAppendChild(configuration, "overWriteSnapshots", 10, "true");
    return configuration;
}
Also used : Element(org.w3c.dom.Element) Parser(io.fabric8.maven.util.Parser)

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)93 IOException (java.io.IOException)83 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)81 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)76 ArrayList (java.util.ArrayList)74 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)73 Map (java.util.Map)72 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)66 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)66 List (java.util.List)63 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Service (io.fabric8.kubernetes.api.model.Service)51 Collectors (java.util.stream.Collectors)49 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)48 Quantity (io.fabric8.kubernetes.api.model.Quantity)48 ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)46 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)44