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/");
}
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;
}
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;
}
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);
}
}
}
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;
}
}
Aggregations