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