Skip to content

Commit

Permalink
Merge pull request hal#368 from hpehl/HAL-1653
Browse files Browse the repository at this point in the history
HAL-1653: Fix wrong composite failure construction in timeout handler
  • Loading branch information
hpehl authored Feb 12, 2020
2 parents b0b2970 + 437b259 commit 1d56559
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ public void onSuccess(FlowContext context) {
// Restore pending visualization
hosts.stream()
.filter(hostActions::isPending)
.forEach(host -> ItemMonitor
.startProgress(Ids.host(host.getAddressName())));
.forEach(host -> ItemMonitor.startProgress(Ids.host(host.getAddressName())));
}
});
setItemsProvider(itemsProvider);
Expand Down
103 changes: 63 additions & 40 deletions core/src/main/java/org/jboss/hal/core/runtime/TopologyTasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,16 @@ public Completable call(FlowContext context) {
Operation operation = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION)
.param(CHILD_TYPE, ModelDescriptionConstants.HOST)
.build();
completable = dispatcher.execute(operation).doOnSuccess(result -> {
List<String> hostNames = result.asList().stream()
.map(ModelNode::asString)
.collect(toList());
context.set(HOST_NAMES, hostNames);
}).toCompletable();
completable = dispatcher.execute(operation)
.doOnSuccess(result -> {
List<String> hostNames = result.asList().stream()
.map(ModelNode::asString)
.collect(toList());
context.set(HOST_NAMES, hostNames);
})
.doOnError(throwable -> logger.error("TopologyTasks.HostNames failed: {}",
throwable.getMessage()))
.toCompletable();
}
return completable;
}
Expand Down Expand Up @@ -388,6 +392,8 @@ public Completable call(FlowContext context) {
servers.add(server);
});
})
.doOnError(throwable -> logger.error("TopologyTasks.Hosts failed: {}",
throwable.getMessage()))
.onErrorResumeNext(new HostError<>(host, hosts,
error -> new CompositeResult(new ModelNode())))
.toCompletable();
Expand Down Expand Up @@ -422,34 +428,38 @@ public Completable call(FlowContext context) {
.param(SELECT, new ModelNode().add(EVENTS))
.param(WHERE, new ModelNode().set(CONNECTED, false))
.build();
completable = dispatcher.execute(operation).doOnSuccess(result -> {
List<Host> disconnectedHosts = result.asList().stream()
.filter(node -> !node.isFailure())
.map(node -> {
String name = new ResourceAddress(node.get(ADDRESS)).lastValue();
long registered = 0;
long unregistered = 0;
for (ModelNode event : failSafeList(node, RESULT + "/" + EVENTS)) {
if (event.hasDefined(TYPE) && event.hasDefined(TIMESTAMP)) {
if (REGISTERED.equals(event.get(TYPE).asString())) {
registered = max(registered, event.get(TIMESTAMP).asLong());
} else if (UNREGISTERED.equals(event.get(TYPE).asString())) {
unregistered = max(unregistered, event.get(TIMESTAMP).asLong());
completable = dispatcher.execute(operation)
.doOnSuccess(result -> {
List<Host> disconnectedHosts = result.asList().stream()
.filter(node -> !node.isFailure())
.map(node -> {
String name = new ResourceAddress(node.get(ADDRESS)).lastValue();
long registered = 0;
long unregistered = 0;
for (ModelNode event : failSafeList(node, RESULT + "/" + EVENTS)) {
if (event.hasDefined(TYPE) && event.hasDefined(TIMESTAMP)) {
if (REGISTERED.equals(event.get(TYPE).asString())) {
registered = max(registered, event.get(TIMESTAMP).asLong());
} else if (UNREGISTERED.equals(event.get(TYPE).asString())) {
unregistered = max(unregistered, event.get(TIMESTAMP).asLong());
}
}
}
}
}
Date disconnected = unregistered != 0 ? new Date(unregistered) : null;
Date lastConnected = registered != 0 ? new Date(registered) : null;
return Host.disconnected(name, disconnected, lastConnected);
})
.collect(toList());
List<Host> hosts = context.get(HOSTS);
if (hosts == null) {
hosts = new ArrayList<>();
context.set(HOSTS, hosts);
}
hosts.addAll(disconnectedHosts);
}).toCompletable();
Date disconnected = unregistered != 0 ? new Date(unregistered) : null;
Date lastConnected = registered != 0 ? new Date(registered) : null;
return Host.disconnected(name, disconnected, lastConnected);
})
.collect(toList());
List<Host> hosts = context.get(HOSTS);
if (hosts == null) {
hosts = new ArrayList<>();
context.set(HOSTS, hosts);
}
hosts.addAll(disconnectedHosts);
})
.doOnError(throwable -> logger.error("TopologyTasks.DisconnectedHosts failed: {}",
throwable.getMessage()))
.toCompletable();
}
return completable;
}
Expand All @@ -475,13 +485,17 @@ public Completable call(FlowContext context) {
.param(CHILD_TYPE, ModelDescriptionConstants.SERVER_GROUP)
.param(INCLUDE_RUNTIME, true)
.build();
completable = dispatcher.execute(operation).doOnSuccess(result -> {
List<ServerGroup> serverGroups = result.asPropertyList().stream()
.map(ServerGroup::new)
.sorted(comparing(ServerGroup::getName))
.collect(toList());
context.set(SERVER_GROUPS, serverGroups);
}).toCompletable();
completable = dispatcher.execute(operation)
.doOnSuccess(result -> {
List<ServerGroup> serverGroups = result.asPropertyList().stream()
.map(ServerGroup::new)
.sorted(comparing(ServerGroup::getName))
.collect(toList());
context.set(SERVER_GROUPS, serverGroups);
})
.doOnError(throwable -> logger.error("TopologyTasks.ServerGroups failed: {}",
throwable.getMessage()))
.toCompletable();
}
return completable;
}
Expand Down Expand Up @@ -516,6 +530,8 @@ public Completable call(FlowContext context) {
.doOnSuccess(result -> result.asPropertyList().stream()
.map(property -> new Server(host, property))
.forEach(servers::add))
.doOnError(throwable -> logger.error("TopologyTasks.ServersOfHost failed: {}",
throwable.getMessage()))
.toCompletable();
}
return completable;
Expand Down Expand Up @@ -563,6 +579,9 @@ public Completable call(FlowContext context) {
return new Server(h, modelNode.get(RESULT));
})
.forEach(servers::add))
.doOnError(throwable -> logger.error(
"TopologyTasks.ServersOfServerGroup failed: {}",
throwable.getMessage()))
.onErrorResumeNext(error -> {
logger.warn("Unable to read servers of host {}: {}", host,
error.getMessage());
Expand Down Expand Up @@ -633,6 +652,8 @@ public Completable call(FlowContext context) {
return new Server(h, modelNode.get(RESULT));
})
.forEach(servers::add))
.doOnError(throwable -> logger.error("TopologyTasks.RunningServers failed: {}",
throwable.getMessage()))
.onErrorResumeNext(error -> {
logger.warn("Unable to read servers of host {}: {}", host,
error.getMessage());
Expand Down Expand Up @@ -703,6 +724,8 @@ public Completable call(FlowContext context) {
}
}
})
.doOnError(throwable -> logger.error("TopologyTasks.StartedServers failed: {}",
throwable.getMessage()))
.toCompletable();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.jboss.hal.meta.processing.MetadataProcessor.MetadataCallback;
import org.jboss.hal.resources.Ids;
import org.jboss.hal.resources.Resources;
import org.jboss.hal.resources.UIConstants;
import org.jboss.hal.spi.Footer;
import org.jboss.hal.spi.Message;
import org.jboss.hal.spi.MessageEvent;
Expand All @@ -61,6 +62,7 @@
import static org.jboss.hal.core.runtime.Timeouts.hostTimeout;
import static org.jboss.hal.dmr.ModelDescriptionConstants.*;
import static org.jboss.hal.dmr.dispatch.TimeoutHandler.repeatUntilTimeout;
import static org.jboss.hal.resources.UIConstants.LONG_TIMEOUT;
import static org.jboss.hal.resources.UIConstants.SHORT_TIMEOUT;

public class HostActions implements Timeouts {
Expand Down Expand Up @@ -222,7 +224,7 @@ public void onCompleted() {
setTimeout((o) -> {
pendingDialog.close();
finish(host, servers, Result.SUCCESS, Message.success(successMessage));
}, 666);
}, LONG_TIMEOUT);
}

@Override
Expand Down
15 changes: 8 additions & 7 deletions dmr/src/main/java/org/jboss/hal/dmr/dispatch/TimeoutHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.jboss.hal.dmr.ModelDescriptionConstants.FAILED;
import static org.jboss.hal.dmr.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.hal.dmr.ModelDescriptionConstants.OUTCOME;
import static java.util.stream.Collectors.joining;
import static org.jboss.hal.dmr.ModelDescriptionConstants.*;

/** Executes a DMR operation until a specific condition is met or a timeout occurs. */
public class TimeoutHandler {
Expand Down Expand Up @@ -102,10 +101,12 @@ private static ModelNode operationFailure(String reason) {
}

private static CompositeResult compositeFailure(String reason) {
ModelNode node = new ModelNode();
node.get(OUTCOME).set(FAILED);
node.get(FAILURE_DESCRIPTION).set(reason);
return new CompositeResult(node);
ModelNode step1 = new ModelNode();
step1.get(OUTCOME).set(FAILED);
step1.get(FAILURE_DESCRIPTION).set(reason);
ModelNode steps = new ModelNode();
steps.get("step-1").set(step1);
return new CompositeResult(steps);
}

private TimeoutHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ public interface UIConstants {
/** The time in milliseconds after one modal dialog is closed and the next one is shown. */
double SHORT_TIMEOUT = 111;

/** The timeout for long running operations / actions before some kind of loading indicator is shown */
/** The timeout for medium running operations / actions before some kind of loading indicator is shown */
double MEDIUM_TIMEOUT = 333;

/** The timeout for long running operations / actions before some kind of loading indicator is shown */
double LONG_TIMEOUT = 666;

/** The default polling interval used for {@code setInterval()} */
double POLLING_INTERVAL = 3333;

Expand Down

0 comments on commit 1d56559

Please sign in to comment.