Search in sources :

Example 36 with Build

use of io.fabric8.openshift.api.model.Build 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 37 with Build

use of io.fabric8.openshift.api.model.Build 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)

Example 38 with Build

use of io.fabric8.openshift.api.model.Build in project fabric8 by jboss-fuse.

the class EnsemblePasswordAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (!commit) {
        if (newPassword == null) {
            System.out.println(fabricService.getZookeeperPassword());
        } else {
            String zookeeperUrl = fabricService.getZookeeperUrl();
            String oldPassword = fabricService.getZookeeperPassword();
            System.out.println("Updating the password...");
            // Since we will be changing the password, create a new ZKClient that won't
            // be getting update by the password change.
            CuratorACLManager aclManager = new CuratorACLManager();
            CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(zookeeperUrl).retryPolicy(new RetryOneTime(500)).aclProvider(aclManager).authorization("digest", ("fabric:" + oldPassword).getBytes()).sessionTimeoutMs(30000).build();
            curator.start();
            try {
                // Lets first adjust the acls so that the new password and old passwords work against the ZK paths.
                String digestedIdPass = DigestAuthenticationProvider.generateDigest("fabric:" + newPassword);
                aclManager.registerAcl("/fabric", "auth::acdrw,world:anyone:,digest:" + digestedIdPass + ":acdrw");
                aclManager.fixAcl(curator, "/fabric", true);
                // Ok now lets push out a config update of what the password is.
                curator.setData().forPath(ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath(), PasswordEncoder.encode(newPassword).getBytes(Charsets.UTF_8));
            } finally {
                curator.close();
            }
            // Refresh the default profile to cause all nodes to pickup the new password.
            ProfileService profileService = fabricService.adapt(ProfileService.class);
            for (String ver : profileService.getVersions()) {
                Version version = profileService.getVersion(ver);
                if (version != null) {
                    Profile profile = version.getProfile("default");
                    if (profile != null) {
                        Profiles.refreshProfile(fabricService, profile);
                    }
                }
            }
            System.out.println("");
            System.out.println("Password updated. Please wait a little while for the new password to");
            System.out.println("get delivered as a config update to all the fabric nodes. Once, the ");
            System.out.println("nodes all updated (nodes must be online), please run:");
            System.out.println("");
            System.out.println("  fabric:ensemble-password --commit ");
            System.out.println("");
        }
    } else {
        // Now lets connect with the new password and reset the ACLs so that the old password
        // does not work anymore.
        CuratorACLManager aclManager = new CuratorACLManager();
        CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(fabricService.getZookeeperUrl()).retryPolicy(new RetryOneTime(500)).aclProvider(aclManager).authorization("digest", ("fabric:" + fabricService.getZookeeperPassword()).getBytes()).sessionTimeoutMs(30000).build();
        curator.start();
        try {
            aclManager.fixAcl(curator, "/fabric", true);
            System.out.println("Only the current password is allowed access to fabric now.");
        } finally {
            curator.close();
        }
    }
    return null;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorACLManager(io.fabric8.zookeeper.curator.CuratorACLManager)

Example 39 with Build

use of io.fabric8.openshift.api.model.Build in project fabric8 by jboss-fuse.

the class MavenProxyResolutionTest method releaseIsAvailableInRemoteRepositoryNotUpdatingRelease.

@Test
public void releaseIsAvailableInRemoteRepositoryNotUpdatingRelease() throws IOException, InvalidMavenArtifactRequest {
    File remoteRepository = initFileRepository("rr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("10:00"), "a");
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
    // first resolution
    assertThat(FileUtils.readFileToString(file), equalTo("a"));
    // don't do that, it's not proper use of maven. But sometimes we just have another deployment to public repository...
    mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("11:00"), "b");
    // second resolution
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
    assertThat("Artifact won't be updated for release version", FileUtils.readFileToString(file), equalTo("a"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File) Test(org.junit.Test)

Example 40 with Build

use of io.fabric8.openshift.api.model.Build in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInDefaultRepositoryActingAsRemote.

@Test
public void snapshotIsAvailableInDefaultRepositoryActingAsRemote() throws IOException, InvalidMavenArtifactRequest {
    File differentLocalRepository = initFileRepository("dlr");
    File defaultRepository = initFileRepository("dr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.<File>emptyList()).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER).withDefaultRepositories(Collections.singletonList(defaultRepository)).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnDeploy(differentLocalRepository, defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
    // Here's expected state of repository where SNAPSHOT was `mvn deploy`ed
    assertFalse(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata-local.xml").isFile());
    assertTrue(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml").isFile());
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    boolean checked = false;
    assertThat(metadata.getVersioning().getSnapshot().isLocalCopy(), is(false));
    for (SnapshotVersion snapshotVersion : metadata.getVersioning().getSnapshotVersions()) {
        if ("jar".equals(snapshotVersion.getExtension())) {
            assertThat(snapshotVersion.getVersion(), is("0.1.0-20170101.100000-1"));
            checked = true;
        }
    }
    assertTrue("We should find snapshot metadata", checked);
    // download artifact using version from metadata
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0-20170101.100000-1/universalis-api-0.1.0-20170101.100000-1.jar");
    assertThat(FileUtils.readFileToString(file), equalTo("a"));
    mvnDeploy(differentLocalRepository, defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    metadata = readMetadata(file);
    assertThat("No policy should prevent us from seeing newer snapshot from defaultRepository", metadata.getVersioning().getSnapshotVersions().get(0).getVersion(), is("0.1.0-20170101.110000-2"));
}
Also used : SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)255 ArrayList (java.util.ArrayList)74 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)69 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)68 HashMap (java.util.HashMap)67 File (java.io.File)53 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)51 IOException (java.io.IOException)50 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)45 Pod (io.fabric8.kubernetes.api.model.Pod)38 Map (java.util.Map)35 Service (io.fabric8.kubernetes.api.model.Service)34 FabricService (io.fabric8.api.FabricService)33 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)30 Container (io.fabric8.api.Container)29 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)28 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)27 List (java.util.List)26 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)25 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)25