Search in sources :

Example 21 with Stop

use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by jboss-fuse.

the class DeploymentAgent method doUpdate.

public boolean doUpdate(Dictionary<String, ?> props) throws Exception {
    if (props == null || Boolean.parseBoolean((String) props.get("disabled"))) {
        return false;
    }
    final Hashtable<String, String> properties = new Hashtable<>();
    for (Enumeration e = props.keys(); e.hasMoreElements(); ) {
        Object key = e.nextElement();
        Object val = props.get(key);
        if (!"service.pid".equals(key) && !FeatureConfigInstaller.FABRIC_ZOOKEEPER_PID.equals(key)) {
            properties.put(key.toString(), val.toString());
        }
    }
    updateStatus("analyzing", null);
    // Building configuration
    curatorCompleteService.waitForService(TimeUnit.SECONDS.toMillis(30));
    String httpUrl;
    List<URI> mavenRepoURIs;
    // force reading of updated informations from ZK
    if (!fabricService.isEmpty()) {
        updateMavenRepositoryConfiguration(fabricService.getService());
    }
    try {
        fabricServiceOperations.lock();
        // no one will change the members now
        httpUrl = this.httpUrl;
        mavenRepoURIs = this.mavenRepoURIs;
    } finally {
        fabricServiceOperations.unlock();
    }
    addMavenProxies(properties, httpUrl, mavenRepoURIs);
    final MavenResolver resolver = MavenResolvers.createMavenResolver(properties, "org.ops4j.pax.url.mvn");
    final DownloadManager manager = DownloadManagers.createDownloadManager(resolver, getDownloadExecutor());
    manager.addListener(new DownloadCallback() {

        @Override
        public void downloaded(StreamProvider provider) throws Exception {
            int pending = manager.pending();
            updateStatus(pending > 0 ? "downloading (" + pending + " pending)" : "downloading", null);
        }
    });
    // Update framework, libs, system and config props
    final Object lock = new Object();
    final AtomicBoolean restart = new AtomicBoolean();
    final Set<String> libsToRemove = new HashSet<>(managedLibs.keySet());
    final Set<String> endorsedLibsToRemove = new HashSet<>(managedEndorsedLibs.keySet());
    final Set<String> extensionLibsToRemove = new HashSet<>(managedExtensionLibs.keySet());
    final Set<String> sysPropsToRemove = new HashSet<>(managedSysProps.keySet());
    final Set<String> configPropsToRemove = new HashSet<>(managedConfigProps.keySet());
    final Set<String> etcsToRemove = new HashSet<>(managedEtcs.keySet());
    final Properties configProps = new Properties(new File(KARAF_BASE + File.separator + "etc" + File.separator + "config.properties"));
    final Properties systemProps = new Properties(new File(KARAF_BASE + File.separator + "etc" + File.separator + "system.properties"));
    Downloader downloader = manager.createDownloader();
    for (String key : properties.keySet()) {
        if (key.equals("framework")) {
            String url = properties.get(key);
            if (!url.startsWith("mvn:")) {
                throw new IllegalArgumentException("Framework url must use the mvn: protocol");
            }
            downloader.download(url, new DownloadCallback() {

                @Override
                public void downloaded(StreamProvider provider) throws Exception {
                    File file = provider.getFile();
                    String path = file.getPath();
                    if (path.startsWith(KARAF_HOME)) {
                        path = path.substring(KARAF_HOME.length() + 1);
                    }
                    synchronized (lock) {
                        if (!path.equals(configProps.get("karaf.framework.felix"))) {
                            configProps.put("karaf.framework", "felix");
                            configProps.put("karaf.framework.felix", path);
                            restart.set(true);
                        }
                    }
                }
            });
        } else if (key.startsWith("config.")) {
            String k = key.substring("config.".length());
            String v = properties.get(key);
            synchronized (lock) {
                managedConfigProps.put(k, v);
                configPropsToRemove.remove(k);
                if (!v.equals(configProps.get(k))) {
                    configProps.put(k, v);
                    restart.set(true);
                }
            }
        } else if (key.startsWith("system.")) {
            String k = key.substring("system.".length());
            synchronized (lock) {
                String v = properties.get(key);
                managedSysProps.put(k, v);
                sysPropsToRemove.remove(k);
                if (!v.equals(systemProps.get(k))) {
                    systemProps.put(k, v);
                    restart.set(true);
                }
            }
        } else if (key.startsWith("lib.")) {
            String value = properties.get(key);
            downloader.download(value, new DownloadCallback() {

                @Override
                public void downloaded(StreamProvider provider) throws Exception {
                    File libFile = provider.getFile();
                    String libName = libFile.getName();
                    Long checksum = ChecksumUtils.checksum(libFile);
                    boolean update;
                    synchronized (lock) {
                        managedLibs.put(libName, "true");
                        libsToRemove.remove(libName);
                        update = !Long.toString(checksum).equals(libChecksums.getProperty(libName));
                    }
                    if (update) {
                        Files.copy(libFile, new File(LIB_PATH, libName));
                        restart.set(true);
                    }
                }
            });
        } else if (key.startsWith("endorsed.")) {
            String value = properties.get(key);
            downloader.download(value, new DownloadCallback() {

                @Override
                public void downloaded(StreamProvider provider) throws Exception {
                    File libFile = provider.getFile();
                    String libName = libFile.getName();
                    Long checksum = ChecksumUtils.checksum(new FileInputStream(libFile));
                    boolean update;
                    synchronized (lock) {
                        managedEndorsedLibs.put(libName, "true");
                        endorsedLibsToRemove.remove(libName);
                        update = !Long.toString(checksum).equals(endorsedChecksums.getProperty(libName));
                    }
                    if (update) {
                        Files.copy(libFile, new File(LIB_ENDORSED_PATH, libName));
                        restart.set(true);
                    }
                }
            });
        } else if (key.startsWith("extension.")) {
            String value = properties.get(key);
            downloader.download(value, new DownloadCallback() {

                @Override
                public void downloaded(StreamProvider provider) throws Exception {
                    File libFile = provider.getFile();
                    String libName = libFile.getName();
                    Long checksum = ChecksumUtils.checksum(libFile);
                    boolean update;
                    synchronized (lock) {
                        managedExtensionLibs.put(libName, "true");
                        extensionLibsToRemove.remove(libName);
                        update = !Long.toString(checksum).equals(extensionChecksums.getProperty(libName));
                    }
                    if (update) {
                        Files.copy(libFile, new File(LIB_EXT_PATH, libName));
                        restart.set(true);
                    }
                }
            });
        } else if (key.startsWith("etc.")) {
            String value = properties.get(key);
            downloader.download(value, new DownloadCallback() {

                @Override
                public void downloaded(StreamProvider provider) throws Exception {
                    File etcFile = provider.getFile();
                    String etcName = etcFile.getName();
                    Long checksum = ChecksumUtils.checksum(new FileInputStream(etcFile));
                    boolean update;
                    synchronized (lock) {
                        managedEtcs.put(etcName, "true");
                        etcsToRemove.remove(etcName);
                        update = !Long.toString(checksum).equals(etcChecksums.getProperty(etcName));
                    }
                    if (update) {
                        Files.copy(etcFile, new File(KARAF_ETC, etcName));
                    }
                }
            });
        }
    }
    downloader.await();
    // Remove unused libs, system & config properties
    for (String sysProp : sysPropsToRemove) {
        systemProps.remove(sysProp);
        managedSysProps.remove(sysProp);
        System.clearProperty(sysProp);
        restart.set(true);
    }
    for (String configProp : configPropsToRemove) {
        configProps.remove(configProp);
        managedConfigProps.remove(configProp);
        restart.set(true);
    }
    for (String lib : libsToRemove) {
        File libFile = new File(LIB_PATH, lib);
        libFile.delete();
        libChecksums.remove(lib);
        managedLibs.remove(lib);
        restart.set(true);
    }
    for (String lib : endorsedLibsToRemove) {
        File libFile = new File(LIB_ENDORSED_PATH, lib);
        libFile.delete();
        endorsedChecksums.remove(lib);
        managedEndorsedLibs.remove(lib);
        restart.set(true);
    }
    for (String lib : extensionLibsToRemove) {
        File libFile = new File(LIB_EXT_PATH, lib);
        libFile.delete();
        extensionChecksums.remove(lib);
        managedExtensionLibs.remove(lib);
        restart.set(true);
    }
    for (String etc : etcsToRemove) {
        File etcFile = new File(KARAF_ETC, etc);
        etcFile.delete();
        etcChecksums.remove(etc);
        managedEtcs.remove(etc);
    }
    libChecksums.save();
    endorsedChecksums.save();
    extensionChecksums.save();
    etcChecksums.save();
    managedLibs.save();
    managedEndorsedLibs.save();
    managedExtensionLibs.save();
    managedConfigProps.save();
    managedSysProps.save();
    managedEtcs.save();
    if (restart.get()) {
        updateStatus("restarting", null);
        configProps.save();
        systemProps.save();
        System.setProperty("karaf.restart", "true");
        bundleContext.getBundle(0).stop();
        return false;
    }
    FeatureConfigInstaller configInstaller = null;
    ServiceReference configAdminServiceReference = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
    if (configAdminServiceReference != null) {
        ConfigurationAdmin configAdmin = (ConfigurationAdmin) bundleContext.getService(configAdminServiceReference);
        configInstaller = new FeatureConfigInstaller(bundleContext, configAdmin, manager);
    }
    int bundleStartTimeout = Constants.BUNDLE_START_TIMEOUT;
    String overriddenTimeout = properties.get(Constants.BUNDLE_START_TIMEOUT_PID_KEY);
    try {
        if (overriddenTimeout != null)
            bundleStartTimeout = Integer.parseInt(overriddenTimeout);
    } catch (Exception e) {
        LOGGER.warn("Failed to set {} value: [{}], applying default value: {}", Constants.BUNDLE_START_TIMEOUT_PID_KEY, overriddenTimeout, Constants.BUNDLE_START_TIMEOUT);
    }
    Agent agent = new Agent(bundleContext.getBundle(), systemBundleContext, manager, configInstaller, null, DEFAULT_FEATURE_RESOLUTION_RANGE, DEFAULT_BUNDLE_UPDATE_RANGE, DEFAULT_UPDATE_SNAPSHOTS, bundleContext.getDataFile(STATE_FILE), bundleStartTimeout) {

        @Override
        public void updateStatus(String status) {
            DeploymentAgent.this.updateStatus(status, null, false);
        }

        @Override
        public void updateStatus(String status, boolean force) {
            DeploymentAgent.this.updateStatus(status, null, force);
        }

        @Override
        protected void saveState(State newState) throws IOException {
            super.saveState(newState);
            DeploymentAgent.this.state.replace(newState);
        }

        @Override
        protected void provisionList(Set<Resource> resources) {
            DeploymentAgent.this.provisionList = resources;
        }

        @Override
        protected boolean done(boolean agentStarted, List<String> urls) {
            if (agentStarted) {
                // let's do patch-management "last touch" only if new agent wasn't started.
                return true;
            }
            // agent finished provisioning, we can call back to low level patch management
            ServiceReference<PatchManagement> srPm = systemBundleContext.getServiceReference(PatchManagement.class);
            ServiceReference<FabricService> srFs = systemBundleContext.getServiceReference(FabricService.class);
            if (srPm != null && srFs != null) {
                PatchManagement pm = systemBundleContext.getService(srPm);
                FabricService fs = systemBundleContext.getService(srFs);
                if (pm != null && fs != null) {
                    LOGGER.info("Validating baseline information");
                    this.updateStatus("validating baseline information", true);
                    Profile profile = fs.getCurrentContainer().getOverlayProfile();
                    Map<String, String> versions = profile.getConfiguration("io.fabric8.version");
                    File localRepository = resolver.getLocalRepository();
                    if (pm.alignTo(versions, urls, localRepository, new PatchSynchronization())) {
                        this.updateStatus("requires full restart", true);
                        // let's reuse the same flag
                        restart.set(true);
                        return false;
                    }
                    if (handleRestartJvmFlag(profile, restart)) {
                        return false;
                    }
                }
            }
            return true;
        }
    };
    agent.setDeploymentAgentId(deploymentAgentId);
    agent.provision(getPrefixedProperties(properties, "repository."), getPrefixedProperties(properties, "feature."), getPrefixedProperties(properties, "bundle."), getPrefixedProperties(properties, "req."), getPrefixedProperties(properties, "override."), getPrefixedProperties(properties, "optional."), getMetadata(properties, "metadata#"));
    if (restart.get()) {
        // prevent updating status to "success"
        return false;
    }
    return true;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) DownloadCallback(io.fabric8.agent.download.DownloadCallback) Downloader(io.fabric8.agent.download.Downloader) Properties(org.apache.felix.utils.properties.Properties) URI(java.net.URI) DownloadManager(io.fabric8.agent.download.DownloadManager) Profile(io.fabric8.api.Profile) PatchManagement(io.fabric8.patch.management.PatchManagement) MavenResolver(io.fabric8.maven.MavenResolver) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Agent(io.fabric8.agent.service.Agent) StreamProvider(io.fabric8.agent.download.StreamProvider) Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) ConfigurationException(org.osgi.service.cm.ConfigurationException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ServiceReference(org.osgi.framework.ServiceReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FeatureConfigInstaller(io.fabric8.agent.service.FeatureConfigInstaller) State(io.fabric8.agent.service.State) FabricService(io.fabric8.api.FabricService) File(java.io.File) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 22 with Stop

use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceImpl method replacePatchManagementBundleInStartupPropertiesIfNecessary.

/**
 * One stop method that does everything related to installing patch-management bundle in etc/startup.properties.
 * It removes old version of the bundle, doesn't do anything if the bundle is already there and appends a declaration if there was none.
 * @param git
 * @param bundleVersion
 * @throws IOException
 * @throws GitAPIException
 */
private RevCommit replacePatchManagementBundleInStartupPropertiesIfNecessary(Git git, String bundleVersion) throws IOException, GitAPIException {
    boolean modified = false;
    boolean installed = false;
    File etcStartupProperties = new File(git.getRepository().getWorkTree(), "etc/startup.properties");
    List<String> lines = FileUtils.readLines(etcStartupProperties);
    List<String> newVersion = new LinkedList<>();
    for (String line : lines) {
        if (!line.startsWith("io/fabric8/patch/patch-management/")) {
            // copy unchanged
            newVersion.add(line);
        } else {
            // is it old, same, (newer??) version?
            Matcher matcher = VERSION_PATTERN.matcher(line);
            if (matcher.find()) {
                // it should match
                String alreadyInstalledVersion = matcher.group(1);
                Version v1 = Utils.getOsgiVersion(alreadyInstalledVersion);
                Version v2 = Utils.getOsgiVersion(bundleVersion);
                if (v1.equals(v2)) {
                    // already installed at correct version
                    installed = true;
                } else if (v1.compareTo(v2) < 0) {
                    // we'll install new version
                    modified = true;
                } else {
                // newer installed? why?
                }
            }
        }
    }
    if (modified || !installed) {
        newVersion.add("");
        newVersion.add("# installed by patch-management");
        newVersion.add(String.format("io/fabric8/patch/patch-management/%s/patch-management-%s.jar=%d", bundleVersion, bundleVersion, Activator.PATCH_MANAGEMENT_START_LEVEL));
        StringBuilder sb = new StringBuilder();
        for (String newLine : newVersion) {
            sb.append(newLine).append("\n");
        }
        FileUtils.write(new File(git.getRepository().getWorkTree(), "etc/startup.properties"), sb.toString());
        // now to git working copy
        git.add().addFilepattern("etc/startup.properties").call();
        RevCommit commit = gitPatchRepository.prepareCommit(git, String.format(MARKER_PATCH_MANAGEMENT_INSTALLATION_COMMIT_PATTERN, bundleVersion)).call();
        // "checkout" the above change in main "working copy" (${karaf.home})
        applyChanges(git, commit.getParent(0), commit);
        Activator.log(LogService.LOG_INFO, String.format("patch-management-%s.jar installed in etc/startup.properties.", bundleVersion));
        return commit;
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) Version(org.osgi.framework.Version) Artifact.isSameButVersion(io.fabric8.patch.management.Artifact.isSameButVersion) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) LinkedList(java.util.LinkedList) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 23 with Stop

use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceIT method addPatch4.

/**
 * Patch 4 is rollup patch (doesn't contain descriptor, contains default.profile/io.fabric8.version.properties)
 * Adding it is not different that adding non-rollup patch. Installation is different
 * @throws IOException
 * @throws GitAPIException
 */
@Test
public void addPatch4() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData = service.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL()).get(0);
    assertThat(patchData.getId(), equalTo("patch-4"));
    Patch patch = service.trackPatch(patchData);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    // we should see remote branch for the patch, but without checking it out, it won't be available in the clone's local branches
    List<Ref> branches = fork.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
    Ref patchBranch = null;
    for (Ref remoteBranch : branches) {
        if (String.format("refs/remotes/origin/patch-%s", patchData.getId()).equals(remoteBranch.getName())) {
            patchBranch = remoteBranch;
            break;
        }
    }
    assertNotNull("Should find remote branch for the added patch", patchBranch);
    assertThat(patch.getManagedPatch().getCommitId(), equalTo(patchBranch.getObjectId().getName()));
    RevCommit patchCommit = new RevWalk(fork.getRepository()).parseCommit(patchBranch.getObjectId());
    // patch commit should be child of baseline commit
    RevCommit baselineCommit = new RevWalk(fork.getRepository()).parseCommit(patchCommit.getParent(0));
    // this baseline commit should be tagged "baseline-VERSION"
    Ref tag = fork.tagList().call().get(0);
    assertThat(tag.getName(), equalTo("refs/tags/baseline-6.2.0"));
    RevCommit baselineCommitFromTag = new RevWalk(fork.getRepository()).parseCommit(tag.getTarget().getObjectId());
    assertThat(baselineCommit.getId(), equalTo(baselineCommitFromTag.getId()));
    List<DiffEntry> patchDiff = repository.diff(fork, baselineCommit, patchCommit);
    int changes = SystemUtils.IS_OS_WINDOWS ? 8 : 9;
    assertThat("patch-4 should lead to " + changes + " changes", patchDiff.size(), equalTo(changes));
    for (Iterator<DiffEntry> iterator = patchDiff.iterator(); iterator.hasNext(); ) {
        DiffEntry de = iterator.next();
        if ("bin/start".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("bin/stop".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if (!SystemUtils.IS_OS_WINDOWS && "bin/setenv".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("etc/startup.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("etc/my.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.ADD) {
            iterator.remove();
        }
        if ("etc/system.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("fabric/import/fabric/profiles/default.profile/io.fabric8.agent.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("fabric/import/fabric/profiles/default.profile/io.fabric8.version.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("patch-info.txt".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.ADD) {
            iterator.remove();
        }
    }
    assertThat("Unknown changes in patch-4", patchDiff.size(), equalTo(0));
    // let's see the patch applied to baseline-6.2.0
    fork.checkout().setName("patch-4").setStartPoint("origin/patch-patch-4").setCreateBranch(true).call();
    String startupProperties = FileUtils.readFileToString(new File(fork.getRepository().getWorkTree(), "etc/startup.properties"));
    assertTrue(startupProperties.contains("org/ops4j/pax/url/pax-url-gopher/2.4.0/pax-url-gopher-2.4.0.jar=5"));
    repository.closeRepository(fork, true);
}
Also used : GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Ref(org.eclipse.jgit.lib.Ref) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Test(org.junit.Test)

Example 24 with Stop

use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by jboss-fuse.

the class ResolverTest method testResolverInheritanceOnChild.

@Test
public void testResolverInheritanceOnChild() throws Exception {
    System.out.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning -g localip -r manualip --manual-ip localhost -b localhost"));
    // System.out.println(executeCommand("shell:info"));
    // System.out.println(executeCommand("fabric:info"));
    // System.out.println(executeCommand("fabric:profile-list"));
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
        Set<Container> containers = ContainerBuilder.create(1, 1).withName("basic.cntG").withProfiles("default").assertProvisioningResult().build(fabricService);
        try {
            Container cntG = containers.iterator().next();
            Assert.assertEquals("manualip", getSubstitutedPath(curator, ZkPath.CONTAINER_RESOLVER.getPath(cntG.getId())));
            Assert.assertEquals("manualip", fabricService.getCurrentContainer().getResolver());
            // We stop the config admin bridge, since the next step is going to hung the container if we do propagate the change to config admin.
            // new BundleUtils(bundleContext).findAndStopBundle("io.fabric8.fabric-configadmin");
            // We want to make sure that the child points to the parent, so we change the parent resolvers and assert.
            System.out.println(CommandSupport.executeCommand("fabric:container-resolver-set --container root localip"));
            Assert.assertEquals("localip", getSubstitutedPath(curator, ZkPath.CONTAINER_RESOLVER.getPath(cntG.getId())));
        } finally {
            ContainerBuilder.destroy(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 25 with Stop

use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by jboss-fuse.

the class ArchetypeTest method testCreateArchetype.

@Test
public void testCreateArchetype() throws Exception {
    ArchetypeInfo archetype = archetypeIdToArchetypeInfoMap.get(archetypeId);
    assertNotNull("No archetype found for id: " + archetypeId, archetype);
    File mavenSettingsFile = getMavenSettingsFile();
    assertFileExists(mavenSettingsFile);
    // create a fabric
    // generate and deploy archetypes
    File workDir = new File(System.getProperty("basedir", "."), "target/generated-projects");
    workDir.mkdirs();
    String profileId = assertGenerateArchetype(archetype, workDir, mavenSettingsFile);
    assertNotNull("Should have a profile ID for " + archetype, profileId);
    FabricRequirements requirements = fabricController.getRequirements();
    if (!addedBroker) {
        addedBroker = true;
        requirements.profile("mq-default").minimumInstances(1);
        FabricAssertions.assertRequirementsSatisfied(fabricController, requirements);
    }
    // deploying each profile should have caused the requirements to be updated to add them all now
    // so lets load the requirements and assert they are satisfied
    requirements.profile(profileId).minimumInstances(1);
    FabricAssertions.assertRequirementsSatisfied(fabricController, requirements);
    System.out.println();
    System.out.println("Managed to create a container for " + profileId + ". Now lets stop it");
    System.out.println();
    // now lets force the container to be stopped
    requirements.profile(profileId).minimumInstances(0).maximumInstances(0);
    FabricAssertions.assertRequirementsSatisfied(fabricController, requirements);
    System.out.println();
    System.out.println("Stopped a container for " + profileId + ". Now lets clear requirements");
    System.out.println();
    requirements.removeProfileRequirements(profileId);
    FabricAssertions.assertRequirementsSatisfied(fabricController, requirements);
    System.out.println();
    System.out.println("Removed requirements for profile " + profileId);
    System.out.println();
}
Also used : FabricRequirements(io.fabric8.api.FabricRequirements) File(java.io.File) Test(org.junit.Test)

Aggregations

Container (io.fabric8.api.Container)7 FabricService (io.fabric8.api.FabricService)7 IOException (java.io.IOException)7 File (java.io.File)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 BundleException (org.osgi.framework.BundleException)5 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)4 URISyntaxException (java.net.URISyntaxException)4 Bundle (org.osgi.framework.Bundle)4 FabricException (io.fabric8.api.FabricException)3 HashMap (java.util.HashMap)3 Session (com.jcraft.jsch.Session)2 Downloader (io.fabric8.agent.download.Downloader)2 StreamProvider (io.fabric8.agent.download.StreamProvider)2 Watch (io.fabric8.kubernetes.client.Watch)2 Watcher (io.fabric8.kubernetes.client.Watcher)2 MavenResolver (io.fabric8.maven.MavenResolver)2 Parser (io.fabric8.maven.util.Parser)2 BundleUpdate (io.fabric8.patch.management.BundleUpdate)2