Search in sources :

Example 1 with Group

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

the class OpenShiftDeployAgent method activate.

@Activate
void activate(Map<String, ?> configuration) {
    // this.realm =  properties != null && properties.containsKey(REALM_PROPERTY_NAME) ? properties.get(REALM_PROPERTY_NAME) : DEFAULT_REALM;
    // this.role =  properties != null && properties.containsKey(ROLE_PROPERTY_NAME) ? properties.get(ROLE_PROPERTY_NAME) : DEFAULT_ROLE;
    group = new ZooKeeperGroup(curator.get(), ZkPath.OPENSHIFT.getPath(), ControllerNode.class);
    group.add(this);
    group.update(createState());
    group.start();
    activateComponent();
}
Also used : ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) Activate(org.apache.felix.scr.annotations.Activate)

Example 2 with Group

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

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

the class GitHttpServerRegistrationHandler method updateMasterUrl.

private void updateMasterUrl(Group<GitNode> group) {
    try {
        if (group.isMaster()) {
            LOGGER.debug("Git repo is the master");
            if (!isMaster.getAndSet(true)) {
                registerServlet(dataPath, realm, roles);
            }
        } else {
            LOGGER.debug("Git repo is not the master");
            if (isMaster.getAndSet(false)) {
                unregisterServlet();
            }
        }
        GitNode state = createState();
        group.update(state);
        String url = state.getUrl();
        gitRemoteUrl.set(ZooKeeperUtils.getSubstitutedData(curator.get(), url));
    } catch (Exception e) {
        LOGGER.debug("Failed to update master git server url.", e);
    }
}
Also used : GitNode(io.fabric8.git.GitNode) InstanceNotFoundException(javax.management.InstanceNotFoundException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 4 with Group

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

the class ZooKeeperGroupTest method testMaster_withStaleNodes1.

@Test
public void testMaster_withStaleNodes1() throws Exception {
    // stale
    putChildData(group, PATH + "/001", "container1");
    putChildData(group, PATH + "/002", "container1");
    // stale
    putChildData(group, PATH + "/003", "container2");
    // stale
    putChildData(group, PATH + "/004", "container3");
    putChildData(group, PATH + "/005", "container2");
    putChildData(group, PATH + "/006", "container3");
    NodeState master = group.master();
    assertThat(master, notNullValue());
    assertThat(master.getContainer(), equalTo("container1"));
}
Also used : NodeState(io.fabric8.groups.NodeState) Test(org.junit.Test)

Example 5 with Group

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

the class ZooKeeperGroupTest method testMaster.

@Test
public void testMaster() throws Exception {
    putChildData(group, PATH + "/001", "container1");
    putChildData(group, PATH + "/002", "container2");
    putChildData(group, PATH + "/003", "container3");
    NodeState master = group.master();
    assertThat(master, notNullValue());
    assertThat(master.getContainer(), equalTo("container1"));
}
Also used : NodeState(io.fabric8.groups.NodeState) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 CuratorFramework (org.apache.curator.framework.CuratorFramework)12 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)9 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 RetryNTimes (org.apache.curator.retry.RetryNTimes)8 NodeState (io.fabric8.groups.NodeState)7 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)6 File (java.io.File)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Profile (io.fabric8.api.Profile)4 GitNode (io.fabric8.git.GitNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 RuntimeProperties (io.fabric8.api.RuntimeProperties)3 MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)3 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)3 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)3 TcpGateway (io.fabric8.gateway.handlers.tcp.TcpGateway)2 Group (io.fabric8.groups.Group)2