use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class VersionCreateAction method doExecute.
@Override
protected Object doExecute() throws Exception {
String latestVersion = null;
ProfileService profileService = fabricService.adapt(ProfileService.class);
List<String> versions = profileService.getVersions();
if (versions.size() > 0) {
latestVersion = versions.get(versions.size() - 1);
}
if (versionId == null) {
IllegalStateAssertion.assertNotNull(latestVersion, "Cannot default the new version name as there are no versions available");
VersionSequence sequence = new VersionSequence(latestVersion);
versionId = sequence.next().getName();
}
// TODO we maybe want to choose the version which is less than the 'name' if it was specified
// e.g. if you create a version 1.1 then it should use 1.0 if there is already a 2.0
String sourceId = null;
if (parentVersion == null) {
sourceId = latestVersion;
} else {
IllegalStateAssertion.assertTrue(profileService.hasVersion(parentVersion), "Cannot find parent version: " + parentVersion);
sourceId = parentVersion;
}
Version targetVersion;
if (sourceId != null) {
Map<String, String> attributes = new HashMap<String, String>(Collections.singletonMap(Version.PARENT, sourceId));
if (description != null) {
attributes.put(Version.DESCRIPTION, description);
}
targetVersion = profileService.createVersionFrom(sourceId, versionId, attributes);
System.out.println("Created version: " + versionId + " as copy of: " + sourceId);
} else {
VersionBuilder builder = VersionBuilder.Factory.create(versionId);
if (description != null) {
builder.addAttribute(Version.DESCRIPTION, description);
}
targetVersion = profileService.createVersion(builder.getVersion());
System.out.println("Create version: " + versionId);
}
if (defaultVersion == Boolean.TRUE) {
fabricService.setDefaultVersionId(targetVersion.getId());
}
return null;
}
use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class ProfileListAction method printProfiles.
protected void printProfiles(ProfileService profileService, List<Profile> profiles, PrintStream out) {
TablePrinter table = new TablePrinter();
table.columns("id", "# containers", "parents");
for (Profile profile : profiles) {
String versionId = profile.getVersion();
String profileId = profile.getId();
// skip profiles that do not exists (they may have been deleted)
if (profileService.hasProfile(versionId, profileId) && (hidden || !profile.isHidden())) {
int active = fabricService.getAssociatedContainers(versionId, profileId).length;
String parents = Strings.join(profile.getParentIds(), " ");
table.row(profileId, activeContainerCountText(active), parents);
}
}
table.print();
}
use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class ProfileListAction method doExecute.
@Override
protected Object doExecute() throws Exception {
ProfileService profileService = fabricService.adapt(ProfileService.class);
Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
List<Profile> profiles = version.getProfiles();
profiles = sortProfiles(profiles);
printProfiles(profileService, profiles, System.out);
return null;
}
use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class ProfileRefreshAction method doExecute.
@Override
protected Object doExecute() throws Exception {
ProfileService profileService = fabricService.adapt(ProfileService.class);
Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
Profile profile = version.getProfile(profileName);
if (profile != null) {
Profiles.refreshProfile(fabricService, profile);
} else {
System.out.println("Profile " + profileName + " not found.");
return 1;
}
return null;
}
use of io.fabric8.api.ProfileService 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;
}
Aggregations