Search in sources :

Example 11 with FabricService

use of io.fabric8.api.FabricService 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)

Example 12 with FabricService

use of io.fabric8.api.FabricService 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 13 with FabricService

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

the class DeploymentUpdater method updateDeployment.

public void updateDeployment(Git git, File baseDir, CredentialsProvider credentials) throws Exception {
    Set<String> bundles = new LinkedHashSet<String>();
    Set<Feature> features = new LinkedHashSet<Feature>();
    Profile overlayProfile = container.getOverlayProfile();
    Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
    bundles.addAll(effectiveProfile.getBundles());
    AgentUtils.addFeatures(features, fabricService, downloadManager, effectiveProfile);
    if (copyFilesIntoGit) {
        copyDeploymentsIntoGit(git, baseDir, bundles, features);
    } else {
        addDeploymentsIntoPom(git, baseDir, effectiveProfile, bundles, features);
    }
    // now lets do a commit
    String message = "updating deployment";
    git.commit().setMessage(message).call();
    enableDeployDirectory(git, baseDir);
    String branch = GitHelpers.currentBranch(git);
    LOG.info("Pushing deployment changes to branch " + branch + " credentials " + credentials + " for container " + container.getId());
    try {
        Iterable<PushResult> results = git.push().setCredentialsProvider(credentials).setRefSpecs(new RefSpec(branch)).setOutputStream(new LoggingOutputStream(LOG)).call();
        /*
            for (PushResult result : results) {
                LOG.info(result.getMessages());
            }
*/
        LOG.info("Pushed deployment changes to branch " + branch + " for container " + container.getId());
    } catch (GitAPIException e) {
        LOG.error("Failed to push deployment changes to branch " + branch + " for container " + container.getId() + ". Reason: " + e, e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RefSpec(org.eclipse.jgit.transport.RefSpec) LoggingOutputStream(io.fabric8.common.util.LoggingOutputStream) PushResult(org.eclipse.jgit.transport.PushResult) Feature(io.fabric8.agent.model.Feature) Profile(io.fabric8.api.Profile)

Example 14 with FabricService

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

the class OpenShiftDeployAgent method createDeployTask.

private DeploymentUpdater createDeployTask(Container container, Map<String, String> openshiftConfiguration) throws MalformedURLException {
    String webappDir = relativePath(container, openshiftConfiguration, OpenShiftConstants.PROPERTY_DEPLOY_WEBAPPS);
    String deployDir = relativePath(container, openshiftConfiguration, OpenShiftConstants.PROPERTY_DEPLOY_JARS);
    if (webappDir != null || deployDir != null) {
        FabricService fabric = fabricService.get();
        DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabric, downloadExecutor);
        DeploymentUpdater deploymentUpdater = new DeploymentUpdater(downloadManager, fabric, container, webappDir, deployDir);
        deploymentUpdater.setRepositories(Maps.stringValue(openshiftConfiguration, OpenShiftConstants.PROPERTY_REPOSITORIES, OpenShiftConstants.DEFAULT_REPOSITORIES));
        deploymentUpdater.setCopyFilesIntoGit(Maps.booleanValue(openshiftConfiguration, OpenShiftConstants.PROPERTY_COPY_BINARIES_TO_GIT, false));
        return deploymentUpdater;
    }
    return null;
}
Also used : FabricService(io.fabric8.api.FabricService) DownloadManager(io.fabric8.agent.download.DownloadManager)

Example 15 with FabricService

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

the class MQCreateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    MQBrokerConfigDTO dto = createDTO();
    Profile profile = MQManager.createOrUpdateProfile(dto, fabricService, runtimeProperties);
    if (profile == null) {
        return null;
    }
    String profileId = profile.getId();
    System.out.println("MQ profile " + profileId + " ready");
    // assign profile to existing containers
    if (assign != null) {
        String[] assignContainers = assign.split(",");
        MQManager.assignProfileToContainers(fabricService, profile, assignContainers);
    }
    // create containers
    if (create != null) {
        String[] createContainers = create.split(",");
        List<CreateContainerBasicOptions.Builder> builderList = MQManager.createContainerBuilders(dto, fabricService, "child", profileId, dto.version(), createContainers);
        for (CreateContainerBasicOptions.Builder builder : builderList) {
            CreateContainerMetadata[] metadatas;
            try {
                if (builder instanceof CreateChildContainerOptions.Builder) {
                    CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
                    builder = childBuilder.jmxUser(username).jmxPassword(password);
                }
                metadatas = fabricService.createContainers(builder.build());
                // check if there was a FabricAuthenticationException as failure then we can try again
                if (metadatas != null) {
                    for (CreateContainerMetadata meta : metadatas) {
                        if (meta.getFailure() != null && meta.getFailure() instanceof FabricAuthenticationException) {
                            throw (FabricAuthenticationException) meta.getFailure();
                        }
                    }
                }
                ShellUtils.storeFabricCredentials(session, username, password);
            } catch (FabricAuthenticationException fae) {
                // If authentication fails, prompts for credentials and try again.
                if (builder instanceof CreateChildContainerOptions.Builder) {
                    CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
                    promptForJmxCredentialsIfNeeded();
                    metadatas = fabricService.createContainers(childBuilder.jmxUser(username).jmxPassword(password).build());
                    ShellUtils.storeFabricCredentials(session, username, password);
                }
            }
        }
    }
    return null;
}
Also used : FabricAuthenticationException(io.fabric8.api.FabricAuthenticationException) CreateChildContainerOptions(io.fabric8.api.CreateChildContainerOptions) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) Profile(io.fabric8.api.Profile) MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) CreateContainerBasicOptions(io.fabric8.api.CreateContainerBasicOptions)

Aggregations

FabricService (io.fabric8.api.FabricService)80 Container (io.fabric8.api.Container)76 Test (org.junit.Test)52 Profile (io.fabric8.api.Profile)50 BundleContext (org.osgi.framework.BundleContext)29 Version (io.fabric8.api.Version)24 ArrayList (java.util.ArrayList)21 ProfileService (io.fabric8.api.ProfileService)19 HashMap (java.util.HashMap)16 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 HashSet (java.util.HashSet)14 Map (java.util.Map)13 FabricException (io.fabric8.api.FabricException)12 IOException (java.io.IOException)12 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Ignore (org.junit.Ignore)10 File (java.io.File)9 LinkedList (java.util.LinkedList)9 Path (javax.ws.rs.Path)8 FabricRequirements (io.fabric8.api.FabricRequirements)7