use of org.jboss.hal.flow.Outcome in project console by hal.
the class StandaloneDeploymentColumn method uploadDeployment.
private void uploadDeployment() {
Metadata metadata = metadataRegistry.lookup(DEPLOYMENT_TEMPLATE);
Wizard<DeploymentContext, DeploymentState> wizard = new Wizard.Builder<DeploymentContext, DeploymentState>(resources.messages().addResourceTitle(Names.DEPLOYMENT), new DeploymentContext()).addStep(UPLOAD, new UploadDeploymentStep(resources)).addStep(NAMES, new NamesStep(environment, metadata, resources)).onBack((context, currentState) -> currentState == NAMES ? UPLOAD : null).onNext((context, currentState) -> currentState == UPLOAD ? NAMES : null).stayOpenAfterFinish().onFinish((wzd, context) -> {
String name = context.name;
String runtimeName = context.runtimeName;
wzd.showProgress(resources.constants().deploymentInProgress(), resources.messages().deploymentInProgress(name));
series(new FlowContext(progress.get()), new CheckDeployment(dispatcher, name), new UploadOrReplace(environment, dispatcher, name, runtimeName, context.file, context.enabled)).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
wzd.showError(resources.constants().deploymentError(), resources.messages().deploymentError(name), error.getMessage());
}
@Override
public void onSuccess(FlowContext context) {
refresh(Ids.deployment(name));
wzd.showSuccess(resources.constants().uploadSuccessful(), resources.messages().uploadSuccessful(name), resources.messages().view(Names.DEPLOYMENT), cxt -> {
/* nothing to do, deployment is already selected */
});
}
});
}).build();
wizard.show();
}
use of org.jboss.hal.flow.Outcome in project console by hal.
the class TestStep method testConnection.
private void testConnection() {
Context context = wizard().getContext();
List<Task<FlowContext>> tasks = new ArrayList<>();
if (!context.isCreated()) {
// add data source
tasks.add(flowContext -> dispatcher.execute(addOperation(context, statementContext)).doOnSuccess((CompositeResult result) -> context.setCreated(true)).doOnError(throwable -> {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, resources.messages().dataSourceAddError());
}).toCompletable());
}
// check running server(s)
tasks.addAll(runningServers(environment, dispatcher, properties(PROFILE_NAME, statementContext.selectedProfile())));
// test connection
tasks.add(flowContext -> {
List<Server> servers = flowContext.get(TopologyTasks.SERVERS);
ResourceAddress address;
if (!servers.isEmpty()) {
Server server = servers.get(0);
address = server.getServerAddress();
} else if (environment.isStandalone()) {
address = ResourceAddress.root();
} else {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, SafeHtmlUtils.fromString(resources.constants().noRunningServers()));
return Completable.error(new FlowException(resources.messages().testConnectionErrorDomain(), flowContext));
}
address.add(SUBSYSTEM, DATASOURCES).add(context.dataSource.isXa() ? XA_DATA_SOURCE : DATA_SOURCE, context.dataSource.getName());
Operation operation = new Operation.Builder(address, TEST_CONNECTION_IN_POOL).build();
return dispatcher.execute(operation).doOnError(throwable -> {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, resources.messages().testConnectionError(context.dataSource.getName()));
}).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext flowContext, Throwable error) {
String title;
SafeHtml text;
if (flowContext == null) {
title = resources.constants().unknownError();
text = resources.messages().unknownError();
} else {
title = flowContext.get(WIZARD_TITLE);
text = flowContext.get(WIZARD_TEXT);
}
wizard().showError(title, text, error.getMessage(), false);
}
@Override
public void onSuccess(FlowContext flowContext) {
wizard().showSuccess(resources.constants().testConnectionSuccess(), resources.messages().testConnectionSuccess(context.dataSource.getName()), false);
}
});
}
use of org.jboss.hal.flow.Outcome in project console by hal.
the class ManagementOperationsPresenter method reload.
@Override
protected void reload() {
if (environment.isStandalone()) {
ResourceAddress addressFindNP = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
Operation operationFindNP = new Operation.Builder(addressFindNP, FIND_NON_PROGRESSING_OPERATION).build();
ResourceAddress addressMO = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
Operation operationMO = new Operation.Builder(addressMO, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, ACTIVE_OPERATION).build();
dispatcher.execute(new Composite(operationFindNP, operationMO), (CompositeResult result) -> {
ModelNode resultNP = result.step(0).get(RESULT);
ModelNode resultOperations = result.step(1).get(RESULT);
final String nonProgressingId = resultNP.isDefined() ? resultNP.asString() : null;
List<ManagementOperations> activeOps = asNamedNodes(resultOperations.asPropertyList()).stream().map(ManagementOperations::new).peek(activeOp -> {
if (nonProgressingId != null && nonProgressingId.equals(activeOp.getName())) {
activeOp.setAsNonProgressing();
}
}).collect(toList());
getView().update(activeOps);
});
} else {
// return available hosts, to later call a find-non-progressing-operation on each host
Task<FlowContext> hostsTask = context -> {
ResourceAddress address = new ResourceAddress();
Operation operation = new Operation.Builder(address, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
return dispatcher.execute(operation).doOnSuccess(result -> {
List<String> hosts = result.asList().stream().map(ModelNode::asString).collect(toList());
context.set(HOSTS, hosts);
}).toCompletable();
};
// return running servers, to later call a find-non-progressing-operation on each runtime server
Task<FlowContext> serversTask = context -> {
// /host=*/server=*:query(select=[host,name],where={server-state=running})
ResourceAddress address = new ResourceAddress().add(HOST, WILDCARD).add(SERVER, WILDCARD);
Operation operation = new Operation.Builder(address, QUERY).param(SELECT, new ModelNode().add(HOST).add(NAME)).param(WHERE, new ModelNode().set(SERVER_STATE, "running")).build();
return dispatcher.execute(operation).doOnSuccess(result -> {
List<String> servers = Collections.emptyList();
if (result != null && result.isDefined()) {
servers = result.asList().stream().map(r -> hostServerAddress(r.get(RESULT))).collect(toList());
}
context.set("servers", servers);
}).toCompletable();
};
// call find-non-progressing-operation and read-resource of active operations
// on each host and server
Task<FlowContext> findNonProgressingTask = context -> {
List<String> hosts = context.get(HOSTS);
List<String> servers = context.get("servers");
Composite composite = new Composite();
for (String host : hosts) {
ResourceAddress address = new ResourceAddress().add(HOST, host).add(CORE_SERVICE, MANAGEMENT).add(SERVICE, MANAGEMENT_OPERATIONS);
Operation operation = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
composite.add(operation);
ResourceAddress ad = new ResourceAddress(address.clone()).add(ACTIVE_OPERATION, WILDCARD);
Operation operationMO = new Operation.Builder(ad, READ_RESOURCE_OPERATION).build();
composite.add(operationMO);
}
if (!servers.isEmpty()) {
for (String server : servers) {
ResourceAddress address = AddressTemplate.of(server).append(MANAGEMENT_OPERATIONS_TEMPLATE).resolve(statementContext);
Operation findOp = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
composite.add(findOp);
ResourceAddress ad = new ResourceAddress(address.clone()).add(ACTIVE_OPERATION, WILDCARD);
Operation operation = new Operation.Builder(ad, READ_RESOURCE_OPERATION).build();
composite.add(operation);
}
}
return dispatcher.execute(composite).doOnSuccess(response -> {
List<String> nonProgressingOps = new ArrayList<>();
List<ManagementOperations> ops = new ArrayList<>();
for (ModelNode r : response) {
ModelNode result = r.get(RESULT);
if (result != null && result.isDefined()) {
ModelType type = result.getType();
// if model is LIST it is the list of active operations
if (ModelType.LIST.equals(type)) {
for (ModelNode op : result.asList()) {
ModelNode opResult = op.get(RESULT);
// the result has two addresses
// 1) the active-operation address itself, example
// /host=master/server=server-three/core-service=management/service=management-operations/active-operation=1940701884
// 2) the resource address
// /host=master/server=server-three/subsystem=elytron/filesystem-realm=file1
// the active-operation address should be store to later use it to cancel, if needed
// the resource address is displayed to the user
ModelNode activeOpAddress = op.get(ADDRESS);
opResult.get(HAL_ACTIVE_OP_ADDRESS).set(activeOpAddress);
String opId = null;
List<Property> activeOperationAddressList = activeOpAddress.asPropertyList();
for (Property p : activeOperationAddressList) {
if (p.getName().equals(ACTIVE_OPERATION)) {
opId = p.getValue().asString();
}
// store the host and server to later show in the view
if (p.getName().equals(HOST)) {
opResult.get(HAL_ACTIVE_ADDRESS_HOST).set(p.getValue().asString());
}
if (p.getName().equals(SERVER)) {
opResult.get(HAL_ACTIVE_ADDRESS_SERVER).set(p.getValue().asString());
}
}
NamedNode node = new NamedNode(opId, opResult);
ManagementOperations activeOp = new ManagementOperations(node);
ops.add(activeOp);
}
} else {
nonProgressingOps.add(result.asString());
}
}
}
// if there are non progressing operations, mark them in the list
if (!nonProgressingOps.isEmpty()) {
Collections.sort(nonProgressingOps);
for (ManagementOperations mop : ops) {
if (nonProgressingOps.indexOf(mop.getName()) > -1) {
mop.setAsNonProgressing();
}
}
}
context.set("active-operations", ops);
}).toCompletable();
};
series(new FlowContext(progress.get()), hostsTask, serversTask, findNonProgressingTask).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
MessageEvent.fire(getEventBus(), Message.error(SafeHtmlUtils.fromString("Error loading management operations: " + error.getMessage())));
}
@Override
public void onSuccess(FlowContext context) {
List<ManagementOperations> ops = context.get("active-operations");
getView().update(ops);
}
});
}
}
use of org.jboss.hal.flow.Outcome in project console by hal.
the class RollbackWizard method show.
public void show() {
Messages messages = resources.messages();
Wizard.Builder<PatchContext, PatchState> wb = new Wizard.Builder<>(resources.constants().rollback(), new PatchContext());
checkServersState(servers -> {
if (servers != null) {
wb.addStep(CHECK_SERVERS, new CheckRunningServersStep(resources, servers, statementContext.selectedHost()));
}
wb.addStep(ROLLBACK, new org.jboss.hal.client.patching.wizard.RollbackStep(metadata, resources, statementContext.selectedHost(), patchId)).onBack((context, currentState) -> {
PatchState previous = null;
switch(currentState) {
case CHECK_SERVERS:
break;
case ROLLBACK:
previous = CHECK_SERVERS;
break;
default:
break;
}
return previous;
}).onNext((context, currentState) -> {
PatchState next = null;
switch(currentState) {
case CHECK_SERVERS:
next = ROLLBACK;
break;
case ROLLBACK:
break;
default:
break;
}
return next;
}).stayOpenAfterFinish().onFinish((wzd, context) -> {
String name = context.patchId;
wzd.showProgress(resources.constants().rollbackInProgress(), messages.rollbackInProgress(name));
series(new FlowContext(progress.get()), new RollbackTask(statementContext, dispatcher, serverActions, context)).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
wzd.showError(resources.constants().rollbackError(), messages.rollbackError(error.getMessage()), error.getMessage());
}
@Override
public void onSuccess(FlowContext context) {
callback.execute();
wzd.showSuccess(resources.constants().rollbackSuccessful(), messages.rollbackSucessful(name));
}
});
});
Wizard<PatchContext, PatchState> wizard = wb.build();
wizard.show();
});
}
Aggregations