use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ProfileChangeParentsAction method doExecute.
@Override
protected Object doExecute() throws Exception {
Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
Profile profile = version.getRequiredProfile(profileId);
// we can only change parents to existing profiles
Profile[] parents = FabricCommand.getExistingProfiles(fabricService, version, parentIds);
ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
List<String> oldParents = builder.getParents();
for (Profile parent : parents) {
builder.addParent(parent.getId());
}
// remove old parent profiles
for (String oldParent : oldParents) {
if (!parentIds.contains(oldParent)) {
builder.removeParent(oldParent);
}
}
profileService.updateProfile(builder.getProfile());
return null;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerStartAction method doExecute.
protected Object doExecute() throws Exception {
Collection<String> expandedNames = super.expandGlobNames(containers);
for (String containerName : expandedNames) {
validateContainerName(containerName);
Container found = FabricCommand.getContainer(fabricService, containerName);
applyUpdatedCredentials(found);
if (force || !found.isAlive()) {
found.start(force);
} else {
System.err.println("Container " + containerName + " is already started");
}
}
return null;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerStopAction method doExecute.
protected Object doExecute() throws Exception {
Collection<String> expandedNames = super.expandGlobNames(containers);
for (String containerName : expandedNames) {
validateContainerName(containerName);
if (!force && FabricCommand.isPartOfEnsemble(fabricService, containerName)) {
System.out.println("Container is part of the ensemble. If you still want to stop it, please use --force option.");
return null;
}
Container found = FabricCommand.getContainer(fabricService, containerName);
applyUpdatedCredentials(found);
if (found.isAlive()) {
found.stop(force);
found = FabricCommand.getContainer(fabricService, containerName);
if (!found.isAlive()) {
System.out.println("Container '" + found.getId() + "' stopped successfully.");
} else {
// In case of SSH container we can have timing issue with this command
// so we will poll the status of container for a fixed number of times
// if it's not stopped then we will output the message, otherwise we will continue normally
int count = 0;
boolean alive = true;
for (count = 0; count < attemptNumber; count++) {
found = FabricCommand.getContainer(fabricService, containerName);
if (!found.isAlive()) {
alive = false;
} else {
Thread.sleep(pollingInterval);
}
}
if (alive) {
System.out.println("Container '" + found.getId() + "' was not stopped successfully, something went wrong. Check Logs.");
}
}
} else {
System.err.println("Container '" + found.getId() + "' already stopped.");
}
}
return null;
}
use of io.fabric8.api.FabricService 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.FabricService in project fabric8 by jboss-fuse.
the class ProfileRenameAction method doExecute.
@Override
protected Object doExecute() throws Exception {
// but validate the new name
try {
FabricValidations.validateProfileName(newName);
} catch (IllegalArgumentException e) {
// we do not want exception in the server log, so print the error message to the console
System.out.println(e.getMessage());
return 1;
}
Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
if (!version.hasProfile(profileName)) {
System.out.println("Profile " + profileName + " not found.");
return 1;
} else if (version.hasProfile(newName)) {
if (!force) {
System.out.println("New name " + newName + " already exists. Use --force if you want to overwrite.");
return null;
}
}
Profiles.renameProfile(fabricService, version.getId(), profileName, newName, force);
return null;
}
Aggregations