use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class ProjectDeployerImpl method getOrCreateVersion.
private Version getOrCreateVersion(ProjectRequirements requirements) {
ProfileService profileService = fabricService.get().adapt(ProfileService.class);
String versionId = getVersionId(requirements);
Version version = findVersion(fabricService.get(), versionId);
if (version == null) {
String baseId = requirements.getBaseVersion();
baseId = getVersionOrDefaultVersion(fabricService.get(), baseId);
Version baseVersion = findVersion(fabricService.get(), baseId);
if (baseVersion != null) {
version = profileService.createVersionFrom(baseVersion.getId(), versionId, null);
} else {
version = VersionBuilder.Factory.create(versionId).getVersion();
version = profileService.createVersion(version);
}
}
return version;
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class ProjectDeployerTest method testProfileDeploy.
@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testProfileDeploy() throws Exception {
String groupId = "foo";
String artifactId = "bar";
String expectedProfileId = groupId + "-" + artifactId;
String versionId = "1.0";
ProjectRequirements requirements = new ProjectRequirements();
DependencyDTO rootDependency = new DependencyDTO();
requirements.setRootDependency(rootDependency);
rootDependency.setGroupId(groupId);
rootDependency.setArtifactId(artifactId);
rootDependency.setVersion("1.0.0");
List<String> parentProfileIds = Arrays.asList("karaf");
List<String> features = Arrays.asList("cxf", "war");
requirements.setParentProfiles(parentProfileIds);
requirements.setFeatures(features);
projectDeployer.deployProject(requirements);
// now we should have a profile created
Profile profile = assertProfileInFabric(expectedProfileId, versionId);
assertBundleCount(profile, 1);
assertEquals("parent ids", parentProfileIds, profile.getParentIds());
assertFeatures(profile, features);
String requirementsFileName = "dependencies/" + groupId + "/" + artifactId + "-requirements.json";
byte[] jsonData = profile.getFileConfiguration(requirementsFileName);
assertNotNull("should have found some JSON for: " + requirementsFileName, jsonData);
String json = new String(jsonData);
LOG.info("Got JSON: " + json);
// lets replace the version, parent, features
rootDependency.setVersion("1.0.1");
projectDeployer.deployProject(requirements);
profile = assertProfileInFabric(expectedProfileId, versionId);
assertBundleCount(profile, 1);
// now lets make a new version
expectedProfileId = "cheese";
versionId = "1.2";
requirements.setVersion(versionId);
requirements.setProfileId(expectedProfileId);
parentProfileIds = Arrays.asList("default");
features = Arrays.asList("camel", "war");
requirements.setParentProfiles(parentProfileIds);
requirements.setFeatures(features);
projectDeployer.deployProject(requirements);
profile = assertProfileInFabric(expectedProfileId, versionId);
assertBundleCount(profile, 1);
assertEquals("parent ids", parentProfileIds, profile.getParentIds());
assertFeatures(profile, features);
// assertProfileMetadata();
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class OpenshiftContainerProvider method create.
@Override
public CreateOpenshiftContainerMetadata create(CreateOpenshiftContainerOptions options, CreationStateListener listener) throws Exception {
assertValid();
IUser user = getOrCreateConnection(options).getUser();
IDomain domain = getOrCreateDomain(user, options);
String cartridgeUrl = null;
Set<String> profiles = options.getProfiles();
String versionId = options.getVersion();
Map<String, String> openshiftConfigOverlay = new HashMap<String, String>();
if (profiles != null && versionId != null) {
ProfileService profileService = fabricService.get().adapt(ProfileService.class);
Version version = profileService.getVersion(versionId);
if (version != null) {
for (String profileId : profiles) {
Profile profile = version.getRequiredProfile(profileId);
if (profile != null) {
Profile overlay = profileService.getOverlayProfile(profile);
Map<String, String> openshiftConfig = overlay.getConfiguration(OpenShiftConstants.OPENSHIFT_PID);
if (openshiftConfig != null) {
openshiftConfigOverlay.putAll(openshiftConfig);
}
}
}
}
cartridgeUrl = openshiftConfigOverlay.get("cartridge");
}
if (cartridgeUrl == null) {
cartridgeUrl = defaultCartridgeUrl;
}
String[] cartridgeUrls = cartridgeUrl.split(" ");
LOG.info("Creating cartridges: " + cartridgeUrl);
String standAloneCartridgeUrl = cartridgeUrls[0];
StandaloneCartridge cartridge;
if (standAloneCartridgeUrl.startsWith(PREFIX_CARTRIDGE_ID)) {
cartridge = new StandaloneCartridge(standAloneCartridgeUrl.substring(PREFIX_CARTRIDGE_ID.length()));
} else {
cartridge = new StandaloneCartridge(new URL(standAloneCartridgeUrl));
}
String zookeeperUrl = fabricService.get().getZookeeperUrl();
String zookeeperPassword = fabricService.get().getZookeeperPassword();
Map<String, String> userEnvVars = null;
if (!options.isEnsembleServer()) {
userEnvVars = new HashMap<String, String>();
userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_URL", zookeeperUrl);
userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD", zookeeperPassword);
String zkPasswordEncode = System.getProperty("zookeeper.password.encode", "true");
userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD_ENCODE", zkPasswordEncode);
userEnvVars.put("OPENSHIFT_FUSE_CREATED_FROM_FABRIC", "true");
}
String initGitUrl = null;
int timeout = IHttpClient.NO_TIMEOUT;
ApplicationScale scale = null;
String containerName = options.getName();
long t0 = System.currentTimeMillis();
IApplication application;
try {
application = domain.createApplication(containerName, cartridge, scale, new GearProfile(options.getGearProfile()), initGitUrl, timeout, userEnvVars);
} catch (OpenShiftTimeoutException e) {
long t1;
do {
Thread.sleep(5000);
domain.refresh();
application = domain.getApplicationByName(containerName);
if (application != null) {
break;
}
t1 = System.currentTimeMillis();
} while (t1 - t0 < TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES));
}
LOG.info("Created application " + containerName);
// now lets add all the embedded cartridges
List<IEmbeddableCartridge> list = new ArrayList<IEmbeddableCartridge>();
for (int idx = 1, size = cartridgeUrls.length; idx < size; idx++) {
String embeddedUrl = cartridgeUrls[idx];
LOG.info("Adding embedded cartridge: " + embeddedUrl);
if (embeddedUrl.startsWith(PREFIX_CARTRIDGE_ID)) {
list.add(new EmbeddableCartridge(embeddedUrl.substring(PREFIX_CARTRIDGE_ID.length())));
} else {
list.add(new EmbeddableCartridge(new URL(embeddedUrl)));
}
}
if (!list.isEmpty()) {
application.addEmbeddableCartridges(list);
}
String gitUrl = application.getGitUrl();
// in case of OpenShiftTimeoutException, application resource doesn't contain getCreationLog().
// actually this method throws NPE
CreateOpenshiftContainerMetadata metadata = new CreateOpenshiftContainerMetadata(domain.getId(), application.getUUID(), application.getMessages() == null ? "" : application.getCreationLog(), gitUrl);
metadata.setContainerName(containerName);
metadata.setCreateOptions(options);
return metadata;
}
use of io.fabric8.api.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/");
}
use of io.fabric8.api.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;
}
Aggregations