use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message 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.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by jboss-fuse.
the class ProfileScaleAction method doExecute.
@Override
protected Object doExecute() throws Exception {
try {
FabricValidations.validateProfileName(name);
} 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;
}
fabricService.scaleProfile(name, count);
ProfileRequirements profileRequirements = fabricService.getRequirements().getOrCreateProfileRequirement(name);
Integer minimumInstances = profileRequirements.getMinimumInstances();
int size = Containers.containersForProfile(fabricService.getContainers(), name).size();
PrintStream output = System.out;
output.println("Profile " + name + " " + (minimumInstances != null ? "now requires " + minimumInstances + " container(s)" : "does not require any containers") + " currently has " + size + " container(s) running");
return null;
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message 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;
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by jboss-fuse.
the class DeployToProfileMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isIgnoreProject())
return;
try {
ProjectRequirements requirements = new ProjectRequirements();
if (isIncludeArtifact()) {
DependencyDTO rootDependency = loadRootDependency();
requirements.setRootDependency(rootDependency);
}
configureRequirements(requirements);
// validate requirements
if (requirements.getProfileId() != null) {
// make sure the profile id is a valid name
FabricValidations.validateProfileName(requirements.getProfileId());
}
boolean newUserAdded = false;
fabricServer = mavenSettings.getServer(serverId);
// we may have username and password from jolokiaUrl
String jolokiaUsername = null;
String jolokiaPassword = null;
try {
URL url = new URL(jolokiaUrl);
String s = url.getUserInfo();
if (Strings.isNotBlank(s) && s.indexOf(':') > 0) {
int idx = s.indexOf(':');
jolokiaUsername = s.substring(0, idx);
jolokiaPassword = s.substring(idx + 1);
customUsernameAndPassword = true;
}
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Option jolokiaUrl is invalid due " + e.getMessage());
}
// jolokia url overrides username/password configured in maven settings
if (jolokiaUsername != null) {
if (fabricServer == null) {
fabricServer = new Server();
}
getLog().info("Using username: " + jolokiaUsername + " and password from provided jolokiaUrl option");
fabricServer.setId(serverId);
fabricServer.setUsername(jolokiaUsername);
fabricServer.setPassword(jolokiaPassword);
}
if (fabricServer == null) {
boolean create = false;
if (mavenSettings.isInteractiveMode() && mavenSettingsWriter != null) {
System.out.println("Maven settings file: " + mavenSettingsFile.getAbsolutePath());
System.out.println();
System.out.println();
System.out.println("There is no <server> section in your ~/.m2/settings.xml file for the server id: " + serverId);
System.out.println();
System.out.println("You can enter the username/password now and have the settings.xml updated or you can do this by hand if you prefer.");
System.out.println();
while (true) {
String value = readInput("Would you like to update the settings.xml file now? (y/n): ").toLowerCase();
if (value.startsWith("n")) {
System.out.println();
System.out.println();
break;
} else if (value.startsWith("y")) {
create = true;
break;
}
}
if (create) {
System.out.println("Please let us know the login details for this server: " + serverId);
System.out.println();
String userName = readInput("Username: ");
String password = readPassword("Password: ");
String password2 = readPassword("Repeat Password: ");
while (!password.equals(password2)) {
System.out.println("Passwords do not match, please try again.");
password = readPassword("Password: ");
password2 = readPassword("Repeat Password: ");
}
System.out.println();
fabricServer = new Server();
fabricServer.setId(serverId);
fabricServer.setUsername(userName);
fabricServer.setPassword(password);
mavenSettings.addServer(fabricServer);
if (mavenSettingsFile.exists()) {
int counter = 1;
while (true) {
File backupFile = new File(mavenSettingsFile.getAbsolutePath() + ".backup-" + counter++ + ".xml");
if (!backupFile.exists()) {
System.out.println("Copied original: " + mavenSettingsFile.getAbsolutePath() + " to: " + backupFile.getAbsolutePath());
Files.copy(mavenSettingsFile, backupFile);
break;
}
}
}
Map<String, Object> config = new HashMap<String, Object>();
mavenSettingsWriter.write(mavenSettingsFile, config, mavenSettings);
System.out.println("Updated settings file: " + mavenSettingsFile.getAbsolutePath());
System.out.println();
newUserAdded = true;
}
}
}
if (fabricServer == null) {
String message = "No <server> element can be found in ~/.m2/settings.xml for the server <id>" + serverId + "</id> so we cannot connect to fabric8!\n\n" + "Please add the following to your ~/.m2/settings.xml file (using the correct user/password values):\n\n" + "<servers>\n" + " <server>\n" + " <id>" + serverId + "</id>\n" + " <username>admin</username>\n" + " <password>admin</password>\n" + " </server>\n" + "</servers>\n";
getLog().error(message);
throw new MojoExecutionException(message);
}
// now lets invoke the mbean
J4pClient client = createJolokiaClient();
if (upload) {
uploadDeploymentUnit(client, newUserAdded || customUsernameAndPassword);
} else {
getLog().info("Uploading to the fabric8 maven repository is disabled");
}
DeployResults results = uploadRequirements(client, requirements);
if (results != null) {
uploadReadMeFile(client, results);
uploadProfileConfigurations(client, results);
refreshProfile(client, results);
}
} catch (MojoExecutionException e) {
throw e;
} catch (Exception e) {
throw new MojoExecutionException("Error executing", e);
}
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by jboss-fuse.
the class HealthCheck method healthList.
@Override
public List<HealthStatus> healthList() {
List<HealthStatus> answer = new ArrayList<HealthStatus>();
FabricStatus status = fabricService.getFabricStatus();
Collection<ProfileStatus> statuses = status.getProfileStatusMap().values();
for (ProfileStatus profile : statuses) {
String id = profile.getProfile();
int instances = profile.getCount();
Integer minimum = profile.getMinimumInstances();
Integer maximum = profile.getMaximumInstances();
double healthPercent = profile.getHealth(instances);
String level = "INFO";
String message = "Profile " + id + " has health " + percentInstance.format(healthPercent);
if (minimum != null) {
if (instances <= 0) {
level = "ERROR";
message = "Profile " + id + " has no instances running! Should have at least " + minimum;
} else if (instances < minimum) {
level = "WARNING";
message = "Profile " + id + " needs more instances running. Should have at least " + minimum + " but currently has only " + instances;
}
}
if (maximum != null && level.equals("INFO") && instances > maximum) {
level = "WARNING";
message = "Profile " + id + " has too many instances running. Should have at most " + maximum + " but currently has only " + instances;
}
answer.add(new HealthStatus("io.fabric8.profileHealth", id, level, message, instances, minimum, maximum, healthPercent));
}
String worries = "";
for (HealthStatus hs : answer) {
if ("WARNING".equals(hs.getLevel()) || "ERROR".equals(hs.getLevel())) {
worries += hs + " , ";
}
}
if ("".equals(worries)) {
this.currentStatus = "Good";
} else {
this.currentStatus = "Getting Worried {" + worries + " }";
}
return answer;
}
Aggregations