Search in sources :

Example 11 with Version

use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.

the class OpenShiftPomDeployerTest method doTest.

protected void doTest(String folder, String[] artifactUrls, String[] repoUrls, String expectedCamelDependencyScope, String expectedHawtioDependencyScope) throws Exception {
    File sourceDir = new File(baseDir, "src/test/resources/" + folder);
    assertDirectoryExists(sourceDir);
    File pomSource = new File(sourceDir, "pom.xml");
    assertFileExists(pomSource);
    File outputDir = new File(baseDir, "target/" + getClass().getName() + "/" + folder);
    outputDir.mkdirs();
    assertDirectoryExists(outputDir);
    File pom = new File(outputDir, "pom.xml");
    Files.copy(pomSource, pom);
    assertFileExists(pom);
    git = Git.init().setDirectory(outputDir).setGitDir(new File(outputDir, ".git")).call();
    assertDirectoryExists(new File(outputDir, ".git"));
    git.add().addFilepattern("pom.xml").call();
    git.commit().setMessage("Initial import").call();
    // now we have the git repo setup; lets run the update
    OpenShiftPomDeployer deployer = new OpenShiftPomDeployer(git, outputDir, deployDir, webAppDir);
    System.out.println("About to update the pom " + pom + " with artifacts: " + Arrays.asList(artifactUrls));
    List<Parser> artifacts = new ArrayList<Parser>();
    for (String artifactUrl : artifactUrls) {
        artifacts.add(Parser.parsePathWithSchemePrefix(artifactUrl));
    }
    List<MavenRepositoryURL> repos = new ArrayList<MavenRepositoryURL>();
    for (String repoUrl : repoUrls) {
        repos.add(new MavenRepositoryURL(repoUrl));
    }
    deployer.update(artifacts, repos);
    System.out.println("Completed the new pom is: ");
    System.out.println(Files.toString(pom));
    Document xml = XmlUtils.parseDoc(pom);
    Element plugins = assertXPathElement(xml, "project/profiles/profile[id = 'openshift']/build/plugins");
    Element cleanExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-clean-plugin']/executions/execution[id = 'fuse-fabric-clean']");
    Element dependencySharedExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-dependency-plugin']/executions/execution[id = 'fuse-fabric-deploy-shared']");
    Element dependencyWebAppsExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-dependency-plugin']/executions/execution[id = 'fuse-fabric-deploy-webapps']");
    Element warPluginWarName = xpath("plugin[artifactId = 'maven-war-plugin']/configuration/warName").element(plugins);
    if (warPluginWarName != null) {
        String warName = warPluginWarName.getTextContent();
        System.out.println("WarName is now:  " + warName);
        assertTrue("Should not have ROOT war name", !"ROOT".equals(warName));
    }
    Element dependencies = assertXPathElement(xml, "project/dependencies");
    Element repositories = assertXPathElement(xml, "project/repositories");
    for (Parser artifact : artifacts) {
        // lets check there's only 1 dependency for group & artifact and it has the right version
        String group = groupId(artifact);
        String artifactId = artifact.getArtifact();
        Element dependency = assertSingleDependencyForGroupAndArtifact(dependencies, group, artifactId);
        Element version = assertXPathElement(dependency, "version");
        assertEquals("Version", artifact.getVersion(), version.getTextContent());
    }
    // lets check we either preserve scope, add provided or don't add a scope if there's none present in the underlying pom
    assertDependencyScope(dependencies, "org.apache.camel", "camel-core", expectedCamelDependencyScope);
    assertDependencyScope(dependencies, "org.drools", "drools-wb-distribution-wars", "provided");
    assertDependencyScope(dependencies, "io.hawt", "hawtio-web", expectedHawtioDependencyScope);
    assertRepositoryUrl(repositories, "https://maven.repository.redhat.com/ga/");
    assertRepositoryUrl(repositories, "https://repo.fusesource.com/nexus/content/groups/ea/");
}
Also used : OpenShiftPomDeployer(io.fabric8.openshift.agent.OpenShiftPomDeployer) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) MavenRepositoryURL(io.fabric8.maven.util.MavenRepositoryURL) Document(org.w3c.dom.Document) File(java.io.File) Parser(io.fabric8.maven.util.Parser)

Example 12 with Version

use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.

the class PatchApplyAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    List<Version> versions;
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    if (versionId != null && !versionId.isEmpty()) {
        Version version = profileService.getRequiredVersion(versionId);
        versions = Collections.singletonList(version);
    } else if (allVersions) {
        versions = new ArrayList<>();
        for (String versionId : profileService.getVersions()) {
            versions.add(profileService.getRequiredVersion(versionId));
        }
    } else {
        versions = Collections.singletonList(fabricService.getRequiredDefaultVersion());
    }
    username = username != null && !username.isEmpty() ? username : ShellUtils.retrieveFabricUser(session);
    password = password != null ? password : ShellUtils.retrieveFabricUserPassword(session);
    promptForJmxCredentialsIfNeeded();
    for (Version version : versions) {
        fabricService.getPatchService().applyPatch(version, patch, username, password);
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) ArrayList(java.util.ArrayList)

Example 13 with Version

use of io.fabric8.kubernetes.model.annotation.Version 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 14 with Version

use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.

the class VersionCreateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    String latestVersion = null;
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    List<String> versions = profileService.getVersions();
    if (versions.size() > 0) {
        latestVersion = versions.get(versions.size() - 1);
    }
    if (versionId == null) {
        IllegalStateAssertion.assertNotNull(latestVersion, "Cannot default the new version name as there are no versions available");
        VersionSequence sequence = new VersionSequence(latestVersion);
        versionId = sequence.next().getName();
    }
    // TODO we maybe want to choose the version which is less than the 'name' if it was specified
    // e.g. if you create a version 1.1 then it should use 1.0 if there is already a 2.0
    String sourceId = null;
    if (parentVersion == null) {
        sourceId = latestVersion;
    } else {
        IllegalStateAssertion.assertTrue(profileService.hasVersion(parentVersion), "Cannot find parent version: " + parentVersion);
        sourceId = parentVersion;
    }
    Version targetVersion;
    if (sourceId != null) {
        Map<String, String> attributes = new HashMap<String, String>(Collections.singletonMap(Version.PARENT, sourceId));
        if (description != null) {
            attributes.put(Version.DESCRIPTION, description);
        }
        targetVersion = profileService.createVersionFrom(sourceId, versionId, attributes);
        System.out.println("Created version: " + versionId + " as copy of: " + sourceId);
    } else {
        VersionBuilder builder = VersionBuilder.Factory.create(versionId);
        if (description != null) {
            builder.addAttribute(Version.DESCRIPTION, description);
        }
        targetVersion = profileService.createVersion(builder.getVersion());
        System.out.println("Create version: " + versionId);
    }
    if (defaultVersion == Boolean.TRUE) {
        fabricService.setDefaultVersionId(targetVersion.getId());
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) HashMap(java.util.HashMap) VersionBuilder(io.fabric8.api.VersionBuilder) VersionSequence(io.fabric8.api.VersionSequence)

Example 15 with Version

use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.

the class ProfileEditAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(profileName);
        if (!(delete || remove)) {
            FabricValidations.validatePidProperties(pidProperties);
        }
    } 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;
    }
    if (delete) {
        set = false;
    }
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getProfile(profileName);
    if (profile != null) {
        editProfile(profile);
    } else {
        System.out.println("Profile " + profileName + " does not exists!");
        return 1;
    }
    return null;
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Aggregations

Map (java.util.Map)87 Version (io.fabric8.api.Version)74 Profile (io.fabric8.api.Profile)70 Test (org.junit.jupiter.api.Test)66 ArrayList (java.util.ArrayList)63 IOException (java.io.IOException)62 File (java.io.File)61 HashMap (java.util.HashMap)61 Vertx (io.vertx.core.Vertx)58 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)57 Test (org.junit.Test)55 Checkpoint (io.vertx.junit5.Checkpoint)54 VertxExtension (io.vertx.junit5.VertxExtension)54 VertxTestContext (io.vertx.junit5.VertxTestContext)54 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)54 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)52 Reconciliation (io.strimzi.operator.common.Reconciliation)50 BeforeAll (org.junit.jupiter.api.BeforeAll)48 Collections (java.util.Collections)46 CoreMatchers.is (org.hamcrest.CoreMatchers.is)46