Search in sources :

Example 6 with Dependency

use of io.fabric8.agent.model.Dependency 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 7 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8 by jboss-fuse.

the class FeatureResource method build.

public static FeatureResource build(Feature feature, String featureRange, Map<String, ? extends Resource> locToRes) throws BundleException {
    FeatureResource resource = new FeatureResource(feature);
    for (BundleInfo info : feature.getBundles()) {
        if (!info.isDependency()) {
            Resource res = locToRes.get(info.getLocation());
            if (res == null) {
                throw new IllegalStateException("Resource not found for url " + info.getLocation());
            }
            addIdentityRequirement(resource, res);
        }
    }
    for (Dependency dep : feature.getDependencies()) {
        if (!dep.isDependency()) {
            addDependency(resource, dep, featureRange);
        }
    }
    for (Capability cap : feature.getCapabilities()) {
        resource.addCapabilities(ResourceBuilder.parseCapability(resource, cap.getValue()));
    }
    for (Requirement req : feature.getRequirements()) {
        resource.addRequirements(ResourceBuilder.parseRequirement(resource, req.getValue()));
    }
    return resource;
}
Also used : ResourceUtils.addIdentityRequirement(io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement) Requirement(io.fabric8.agent.model.Requirement) BundleInfo(io.fabric8.agent.model.BundleInfo) Capability(io.fabric8.agent.model.Capability) Resource(org.osgi.resource.Resource) Dependency(io.fabric8.agent.model.Dependency)

Example 8 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8 by jboss-fuse.

the class FeatureResource method build.

public static FeatureResource build(Feature feature, Conditional conditional, String featureRange, Map<String, ? extends Resource> locToRes) throws BundleException {
    Feature fcond = conditional.asFeature(feature.getName(), feature.getVersion());
    FeatureResource resource = build(fcond, featureRange, locToRes);
    for (String cond : conditional.getCondition()) {
        if (cond.startsWith("req:")) {
            cond = cond.substring("req:".length());
            List<org.osgi.resource.Requirement> reqs = ResourceBuilder.parseRequirement(resource, cond);
            resource.addRequirements(reqs);
        } else {
            Dependency dep = new Dependency();
            String[] p = cond.split("/");
            dep.setName(p[0]);
            if (p.length > 1) {
                dep.setVersion(p[1]);
            }
            addDependency(resource, dep, featureRange, true);
        }
    }
    Dependency dep = new Dependency();
    dep.setName(feature.getName());
    dep.setVersion(feature.getVersion());
    addDependency(resource, dep, featureRange, true);
    return resource;
}
Also used : ResourceUtils.addIdentityRequirement(io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement) Requirement(io.fabric8.agent.model.Requirement) Dependency(io.fabric8.agent.model.Dependency) Feature(io.fabric8.agent.model.Feature)

Example 9 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8 by jboss-fuse.

the class Subsystem method build.

@SuppressWarnings("InfiniteLoopStatement")
public void build(Collection<Feature> features) throws Exception {
    for (Subsystem child : children) {
        child.build(features);
    }
    if (feature != null) {
        for (Dependency dep : feature.getDependencies()) {
            Subsystem ss = this;
            while (!ss.isAcceptDependencies()) {
                ss = ss.getParent();
            }
            ss.requireFeature(dep.getName(), dep.getVersion(), !dep.isDependency());
        }
    }
    List<Requirement> processed = new ArrayList<>();
    while (true) {
        List<Requirement> requirements = getRequirements(IDENTITY_NAMESPACE);
        requirements.addAll(dependentFeatures);
        requirements.removeAll(processed);
        if (requirements.isEmpty()) {
            break;
        }
        for (Requirement requirement : requirements) {
            String name = (String) requirement.getAttributes().get(IDENTITY_NAMESPACE);
            String type = (String) requirement.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
            VersionRange range = (VersionRange) requirement.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
            if (TYPE_FEATURE.equals(type)) {
                for (Feature feature : features) {
                    if (feature.getName().equals(name) && (range == null || range.contains(VersionTable.getVersion(feature.getVersion())))) {
                        if (feature != this.feature) {
                            String ssName = this.name + "#" + (feature.hasVersion() ? feature.getName() + "-" + feature.getVersion() : feature.getName());
                            Subsystem fs = getChild(ssName);
                            if (fs == null) {
                                fs = new Subsystem(ssName, feature, this);
                                fs.build(features);
                                installable.add(fs);
                                children.add(fs);
                            }
                        }
                    }
                }
            }
            processed.add(requirement);
        }
    }
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceUtils.toFeatureRequirement(io.fabric8.agent.resolver.ResourceUtils.toFeatureRequirement) ResourceUtils.addIdentityRequirement(io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement) ArrayList(java.util.ArrayList) VersionRange(org.apache.felix.utils.version.VersionRange) Dependency(io.fabric8.agent.model.Dependency) Feature(io.fabric8.agent.model.Feature)

Example 10 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8 by jboss-fuse.

the class ZooKeeperServerFactory method activateInternal.

private Destroyable activateInternal(BundleContext context, Map<String, ?> configuration) throws Exception {
    LOGGER.info("Creating zookeeper server with: {}", configuration);
    Properties props = new Properties();
    for (Entry<String, ?> entry : configuration.entrySet()) {
        props.put(entry.getKey(), entry.getValue());
    }
    // Remove the dependency on the current dir from dataDir
    String dataDir = props.getProperty("dataDir");
    if (dataDir != null && !Paths.get(dataDir).isAbsolute()) {
        dataDir = runtimeProperties.get().getDataPath().resolve(dataDir).toFile().getAbsolutePath();
        props.setProperty("dataDir", dataDir);
    }
    props.put("clientPortAddress", bootstrapConfiguration.get().getBindAddress());
    // Create myid file
    String serverId = (String) props.get("server.id");
    if (serverId != null) {
        props.remove("server.id");
        File myId = new File(dataDir, "myid");
        if (myId.exists() && !myId.delete()) {
            throw new IOException("Failed to delete " + myId);
        }
        if (myId.getParentFile() == null || (!myId.getParentFile().exists() && !myId.getParentFile().mkdirs())) {
            throw new IOException("Failed to create " + myId.getParent());
        }
        FileOutputStream fos = new FileOutputStream(myId);
        try {
            fos.write((serverId + "\n").getBytes());
        } finally {
            fos.close();
        }
    }
    QuorumPeerConfig peerConfig = getPeerConfig(props);
    if (!peerConfig.getServers().isEmpty()) {
        NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
        cnxnFactory.configure(peerConfig.getClientPortAddress(), peerConfig.getMaxClientCnxns());
        QuorumPeer quorumPeer = new QuorumPeer();
        quorumPeer.setClientPortAddress(peerConfig.getClientPortAddress());
        quorumPeer.setTxnFactory(new FileTxnSnapLog(new File(peerConfig.getDataLogDir()), new File(peerConfig.getDataDir())));
        quorumPeer.setQuorumPeers(peerConfig.getServers());
        quorumPeer.setElectionType(peerConfig.getElectionAlg());
        quorumPeer.setMyid(peerConfig.getServerId());
        quorumPeer.setTickTime(peerConfig.getTickTime());
        quorumPeer.setMinSessionTimeout(peerConfig.getMinSessionTimeout());
        quorumPeer.setMaxSessionTimeout(peerConfig.getMaxSessionTimeout());
        quorumPeer.setInitLimit(peerConfig.getInitLimit());
        quorumPeer.setSyncLimit(peerConfig.getSyncLimit());
        quorumPeer.setQuorumVerifier(peerConfig.getQuorumVerifier());
        quorumPeer.setCnxnFactory(cnxnFactory);
        quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
        quorumPeer.setLearnerType(peerConfig.getPeerType());
        try {
            LOGGER.debug("Starting quorum peer \"{}\" on address {}", quorumPeer.getMyid(), peerConfig.getClientPortAddress());
            quorumPeer.start();
            LOGGER.debug("Started quorum peer \"{}\"", quorumPeer.getMyid());
        } catch (Exception e) {
            LOGGER.warn("Failed to start quorum peer \"{}\", reason : {} ", quorumPeer.getMyid(), e.getMessage());
            quorumPeer.shutdown();
            throw e;
        }
        // Register stats provider
        ClusteredServer server = new ClusteredServer(quorumPeer);
        registration = context.registerService(QuorumStats.Provider.class, server, null);
        return server;
    } else {
        ServerConfig serverConfig = getServerConfig(peerConfig);
        ZooKeeperServer zkServer = new ZooKeeperServer();
        FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(serverConfig.getDataLogDir()), new File(serverConfig.getDataDir()));
        zkServer.setTxnLogFactory(ftxn);
        zkServer.setTickTime(serverConfig.getTickTime());
        zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());
        NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory() {

            protected void configureSaslLogin() throws IOException {
            }
        };
        cnxnFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
        try {
            LOGGER.debug("Starting ZooKeeper server on address {}", peerConfig.getClientPortAddress());
            cnxnFactory.startup(zkServer);
            LOGGER.debug("Started ZooKeeper server");
        } catch (Exception e) {
            LOGGER.warn("Failed to start ZooKeeper server, reason : {}", e);
            cnxnFactory.shutdown();
            throw e;
        }
        // Register stats provider
        SimpleServer server = new SimpleServer(zkServer, cnxnFactory);
        registration = context.registerService(ServerStats.Provider.class, server, null);
        startCleanupManager(serverConfig, props);
        return server;
    }
}
Also used : IOException(java.io.IOException) RuntimeProperties(io.fabric8.api.RuntimeProperties) Properties(java.util.Properties) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IOException(java.io.IOException) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) FileOutputStream(java.io.FileOutputStream) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer) File(java.io.File)

Aggregations

ArrayList (java.util.ArrayList)6 Dependency (io.fabric8.agent.model.Dependency)4 Feature (io.fabric8.agent.model.Feature)4 File (java.io.File)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ResourceUtils.addIdentityRequirement (io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 Parser (io.fabric8.maven.util.Parser)3 HashSet (java.util.HashSet)3 BundleInfo (io.fabric8.agent.model.BundleInfo)2 Requirement (io.fabric8.agent.model.Requirement)2 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)2 DependencyDTO (io.fabric8.deployer.dto.DependencyDTO)2 FailedToResolveDependency (io.fabric8.maven.FailedToResolveDependency)2 URL (java.net.URL)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 DefaultDependencyNode (org.eclipse.aether.graph.DefaultDependencyNode)2 Element (org.w3c.dom.Element)2