Search in sources :

Example 16 with FabricService

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

the class ProfileChangeParentsAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getRequiredProfile(profileId);
    // we can only change parents to existing profiles
    Profile[] parents = FabricCommand.getExistingProfiles(fabricService, version, parentIds);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    List<String> oldParents = builder.getParents();
    for (Profile parent : parents) {
        builder.addParent(parent.getId());
    }
    // remove old parent profiles
    for (String oldParent : oldParents) {
        if (!parentIds.contains(oldParent)) {
            builder.removeParent(oldParent);
        }
    }
    profileService.updateProfile(builder.getProfile());
    return null;
}
Also used : Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 17 with FabricService

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

the class ContainerStartAction method doExecute.

protected Object doExecute() throws Exception {
    Collection<String> expandedNames = super.expandGlobNames(containers);
    for (String containerName : expandedNames) {
        validateContainerName(containerName);
        Container found = FabricCommand.getContainer(fabricService, containerName);
        applyUpdatedCredentials(found);
        if (force || !found.isAlive()) {
            found.start(force);
        } else {
            System.err.println("Container " + containerName + " is already started");
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container)

Example 18 with FabricService

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

the class ContainerStopAction method doExecute.

protected Object doExecute() throws Exception {
    Collection<String> expandedNames = super.expandGlobNames(containers);
    for (String containerName : expandedNames) {
        validateContainerName(containerName);
        if (!force && FabricCommand.isPartOfEnsemble(fabricService, containerName)) {
            System.out.println("Container is part of the ensemble. If you still want to stop it, please use --force option.");
            return null;
        }
        Container found = FabricCommand.getContainer(fabricService, containerName);
        applyUpdatedCredentials(found);
        if (found.isAlive()) {
            found.stop(force);
            found = FabricCommand.getContainer(fabricService, containerName);
            if (!found.isAlive()) {
                System.out.println("Container '" + found.getId() + "' stopped successfully.");
            } else {
                // In case of SSH container we can have timing issue with this command
                // so we will poll the status of container for a fixed number of times
                // if it's not stopped then we will output the message, otherwise we will continue normally
                int count = 0;
                boolean alive = true;
                for (count = 0; count < attemptNumber; count++) {
                    found = FabricCommand.getContainer(fabricService, containerName);
                    if (!found.isAlive()) {
                        alive = false;
                    } else {
                        Thread.sleep(pollingInterval);
                    }
                }
                if (alive) {
                    System.out.println("Container '" + found.getId() + "' was not stopped successfully, something went wrong. Check Logs.");
                }
            }
        } else {
            System.err.println("Container '" + found.getId() + "' already stopped.");
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container)

Example 19 with FabricService

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

the class ProfileRefreshAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getProfile(profileName);
    if (profile != null) {
        Profiles.refreshProfile(fabricService, profile);
    } else {
        System.out.println("Profile " + profileName + " not found.");
        return 1;
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 20 with FabricService

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

the class ProfileRenameAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    // but validate the new name
    try {
        FabricValidations.validateProfileName(newName);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    if (!version.hasProfile(profileName)) {
        System.out.println("Profile " + profileName + " not found.");
        return 1;
    } else if (version.hasProfile(newName)) {
        if (!force) {
            System.out.println("New name " + newName + " already exists. Use --force if you want to overwrite.");
            return null;
        }
    }
    Profiles.renameProfile(fabricService, version.getId(), profileName, newName, force);
    return null;
}
Also used : Version(io.fabric8.api.Version)

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