Search in sources :

Example 86 with Container

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

the class CloudServiceRemove method doExecute.

@Override
protected Object doExecute() throws Exception {
    boolean connected = getCurator().getZookeeperClient().isConnected();
    Container current = null;
    if (connected) {
        deleteSafe(getCurator(), ZkPath.CLOUD_SERVICE.getPath(name));
        current = fabricService.getCurrentContainer();
    }
    // Remove compute configurations for the service.
    Configuration[] computeConfigs = findConfigurationByFactoryPid("org.jclouds.compute");
    if (computeConfigs != null) {
        for (Configuration configuration : computeConfigs) {
            Dictionary props = configuration.getProperties();
            if (props != null) {
                String contextName = (String) props.get(Constants.NAME);
                if (name.equals(contextName)) {
                    configuration.delete();
                }
            }
        }
    }
    return null;
}
Also used : Dictionary(java.util.Dictionary) Container(io.fabric8.api.Container) Configuration(org.osgi.service.cm.Configuration)

Example 87 with Container

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

the class VersionListAction method printVersions.

protected void printVersions(Container[] containers, List<String> versions, String defaultVersionId, PrintStream out) {
    TablePrinter table = new TablePrinter();
    table.columns("version", "default", "# containers", "description");
    List<String> invalidVersion = new ArrayList<String>();
    // they are sorted in the correct order by default
    for (String versionId : versions) {
        if (versionId != null && !versionId.isEmpty() && ALLOWED_PROFILE_NAMES_PATTERN.matcher(versionId).matches()) {
            boolean isDefault = versionId.equals(defaultVersionId);
            Version version = profileService.getRequiredVersion(versionId);
            int active = countContainersByVersion(containers, version);
            String description = version.getAttributes().get(Version.DESCRIPTION);
            table.row(version.getId(), (isDefault ? "true" : ""), activeContainerCountText(active), description);
        } else {
            invalidVersion.add(versionId);
        }
    }
    table.print();
    if (!invalidVersion.isEmpty()) {
        System.out.println("The following profile versions have been skipped since their names are not correct: " + invalidVersion.toString());
    }
}
Also used : CommandUtils.countContainersByVersion(io.fabric8.commands.support.CommandUtils.countContainersByVersion) Version(io.fabric8.api.Version) TablePrinter(io.fabric8.utils.TablePrinter) ArrayList(java.util.ArrayList)

Example 88 with Container

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

the class ProfileWatcherImpl method findProfileArifacts.

// For each profile and version return the map of bundle locations to parsers
private Map<ProfileVersionKey, Map<String, Parser>> findProfileArifacts() throws Exception {
    Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = new HashMap<ProfileVersionKey, Map<String, Parser>>();
    ProfileService profileService = fabricService.get().adapt(ProfileService.class);
    DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabricService.get(), executorService);
    Container[] containers = fabricService.get().getContainers();
    for (Container container : containers) {
        Profile[] profiles = container.getProfiles();
        boolean javaOrProcessContainer = ChildContainers.isJavaOrProcessContainer(fabricService.get(), container);
        // TODO allow filter on a profile here?
        for (Profile profile : profiles) {
            Profile overlay = profileService.getOverlayProfile(profile);
            ProfileVersionKey key = new ProfileVersionKey(profile);
            // if (!profileArtifacts.containsKey(key)) {
            Map<String, Parser> artifacts = null;
            if (javaOrProcessContainer) {
                List<Profile> singletonList = Collections.singletonList(profile);
                artifacts = JavaContainers.getJavaContainerArtifacts(fabricService.get(), singletonList, executorService);
            } else {
                artifacts = AgentUtils.getProfileArtifacts(fabricService.get(), downloadManager, overlay);
            }
            if (artifacts != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Profile " + profile.getId() + " maps to artefacts: " + artifacts.keySet());
                }
                profileArtifacts.put(key, artifacts);
            }
        // }
        }
    }
    return profileArtifacts;
}
Also used : HashMap(java.util.HashMap) DownloadManager(io.fabric8.agent.download.DownloadManager) Profile(io.fabric8.api.Profile) Parser(io.fabric8.maven.util.Parser) Container(io.fabric8.api.Container) ProfileService(io.fabric8.api.ProfileService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 89 with Container

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

the class ProfileWatcherImpl method getCurrentActiveProfileVersions.

/**
 * Gets the set of active profile ids and versions
 */
protected SortedSet<String> getCurrentActiveProfileVersions() {
    SortedSet<String> answer = new TreeSet<String>();
    Container[] containers = fabricService.get().getContainers();
    for (Container container : containers) {
        container.getProvisionList();
        Profile[] profiles = container.getProfiles();
        // TODO allow filter on a profile here?
        for (Profile profile : profiles) {
            String id = profile.getId();
            String version = profile.getVersion();
            answer.add(id + "/" + version);
        }
    }
    return answer;
}
Also used : Container(io.fabric8.api.Container) TreeSet(java.util.TreeSet) Profile(io.fabric8.api.Profile)

Example 90 with Container

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

the class ContainerResource method stop.

/**
 * Stops the container
 */
@DELETE
@Path("start")
public void stop() {
    FabricService fabricService = getFabricService();
    Objects.notNull(fabricService, "fabricService");
    fabricService.stopContainer(container);
}
Also used : FabricService(io.fabric8.api.FabricService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

Container (io.fabric8.api.Container)139 Test (org.junit.Test)75 FabricService (io.fabric8.api.FabricService)56 ArrayList (java.util.ArrayList)39 Container (io.fabric8.kubernetes.api.model.Container)38 IOException (java.io.IOException)38 Profile (io.fabric8.api.Profile)37 HashMap (java.util.HashMap)34 Map (java.util.Map)30 FabricException (io.fabric8.api.FabricException)27 BundleContext (org.osgi.framework.BundleContext)24 Version (io.fabric8.api.Version)23 File (java.io.File)23 HashSet (java.util.HashSet)20 LinkedList (java.util.LinkedList)17 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)16 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)16 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)15 Pod (io.fabric8.kubernetes.api.model.Pod)12 List (java.util.List)12