Skip to content

Commit

Permalink
HAL-1865: Fix adding Infinispan session management resources in distr…
Browse files Browse the repository at this point in the history
…ibutable-web subsystem
  • Loading branch information
hpehl committed Jun 13, 2023
1 parent 5406494 commit 3d79245
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed

- [HAL-1865](https://issues.redhat.com/browse/HAL-1865): Not possible to create Infinispan Session
- Fix visibility of the update manager

## [3.6.7] - 2023-06-13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.Map;
import java.util.Objects;

import javax.inject.Inject;

import org.jboss.hal.ballroom.form.Form;
import org.jboss.hal.core.CrudOperations;
import org.jboss.hal.core.finder.Finder;
Expand Down Expand Up @@ -50,11 +48,15 @@
import org.jboss.hal.spi.MessageEvent;
import org.jboss.hal.spi.Requires;

import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;

import javax.inject.Inject;

import static java.util.Collections.emptyList;
import static org.jboss.hal.client.configuration.subsystem.distributableweb.AddressTemplates.DISTRIBUTABLE_WEB_TEMPLATE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.ADD;
import static org.jboss.hal.dmr.ModelDescriptionConstants.AFFINITY;
Expand Down Expand Up @@ -176,6 +178,32 @@ private void addRouting(Routing newRouting, ModelNode model) {
});
}

void addInfinispanSessionManagement(final String infinispanId, final Metadata metadata) {
AddResourceDialog dialog = new AddResourceDialog(
Ids.build(infinispanId, Ids.TABLE, Ids.ADD),
resources.messages().addResourceTitle(SessionManagement.INFINISPAN.type),
metadata, emptyList(), (name, model) -> {
ResourceAddress sessionAddress = SessionManagement.INFINISPAN.template.resolve(statementContext, name);
Operation sessionOp = new Operation.Builder(sessionAddress, ADD)
.payload(model)
.build();
ResourceAddress affinityAddress = SessionManagement.INFINISPAN.template
.append(AFFINITY + "=" + Affinity.LOCAL.resource)
.resolve(statementContext, name);
Operation affinityOp = new Operation.Builder(affinityAddress, ADD)
.build();
Composite composite = new Composite(sessionOp, affinityOp);
dispatcher.execute(composite, (CompositeResult result) -> {
SafeHtml successMessage = resources.messages().addResourceSuccess(
SessionManagement.INFINISPAN.type, name);
MessageEvent.fire(getEventBus(), Message.success(successMessage));
reload();
}, (__, error) -> MessageEvent.fire(getEventBus(),
Message.error(resources.messages().addResourceError(name, error))));
});
dialog.show();
}

// ------------------------------------------------------ affinity

void saveAffinity(Affinity affinity, Map<String, Object> changedValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.jboss.elemento.EventType;
import org.jboss.hal.ballroom.Attachable;
import org.jboss.hal.ballroom.Tabs;
Expand All @@ -33,7 +31,6 @@
import org.jboss.hal.core.mbui.MbuiViewImpl;
import org.jboss.hal.core.mbui.form.ModelNodeForm;
import org.jboss.hal.core.mbui.table.ModelNodeTable;
import org.jboss.hal.dmr.ModelDescriptionConstants;
import org.jboss.hal.dmr.ModelNode;
import org.jboss.hal.dmr.ModelNodeHelper;
import org.jboss.hal.dmr.NamedNode;
Expand All @@ -47,15 +44,27 @@

import elemental2.dom.HTMLElement;
import elemental2.dom.HTMLSelectElement;
import javax.annotation.PostConstruct;

import static java.util.stream.Collectors.toList;

import static org.jboss.elemento.Elements.*;
import static org.jboss.elemento.Elements.div;
import static org.jboss.elemento.Elements.h;
import static org.jboss.elemento.Elements.label;
import static org.jboss.elemento.Elements.option;
import static org.jboss.elemento.Elements.p;
import static org.jboss.elemento.Elements.section;
import static org.jboss.elemento.Elements.select;
import static org.jboss.elemento.Elements.setVisible;
import static org.jboss.elemento.Elements.span;
import static org.jboss.hal.ballroom.JQuery.$;
import static org.jboss.hal.dmr.ModelDescriptionConstants.AFFINITY;
import static org.jboss.hal.resources.CSS.pfIcon;
import static org.jboss.hal.resources.CSS.selectpicker;
import static org.jboss.hal.resources.Ids.*;
import static org.jboss.hal.resources.Ids.DISTRIBUTABLE_WEB_ROUTING_SELECT;
import static org.jboss.hal.resources.Ids.FORM;
import static org.jboss.hal.resources.Ids.ITEM;
import static org.jboss.hal.resources.Ids.TAB;
import static org.jboss.hal.resources.Ids.build;

@MbuiView
@SuppressWarnings("WeakerAccess")
Expand Down Expand Up @@ -142,7 +151,20 @@ void init() {
// Management";

hotRodSessionManagementForm = createMgmtForm(hotRodId, SessionManagement.HOTROD);
hotRodSessionManagementTable = createMgmtTable(hotRodId, SessionManagement.HOTROD);
Metadata metadata = mbuiContext.metadataRegistry().lookup(SessionManagement.HOTROD.template);
hotRodSessionManagementTable = new ModelNodeTable.Builder<NamedNode>(Ids.build(hotRodId, Ids.TABLE), metadata)
.button(mbuiContext.tableButtonFactory().add(
Ids.build(hotRodId, Ids.TABLE, Ids.ADD),
SessionManagement.HOTROD.type,
SessionManagement.HOTROD.template,
(name, address) -> presenter.reload()))
.button(mbuiContext.tableButtonFactory().remove(
SessionManagement.HOTROD.type,
SessionManagement.HOTROD.template,
table -> table.selectedRow().getName(),
() -> presenter.reload()))
.column("name", (cell, type, row, meta) -> row.getName())
.build();
hotRodSessionManagementAffinityElement = new AffinityElement(SessionManagement.HOTROD, mbuiContext.metadataRegistry(),
mbuiContext.resources());

Expand All @@ -163,7 +185,18 @@ void init() {
SessionManagement.INFINISPAN.type.lastIndexOf(' '));

infinispanSessionManagementForm = createMgmtForm(infinispanId, SessionManagement.INFINISPAN);
infinispanSessionManagementTable = createMgmtTable(infinispanId, SessionManagement.INFINISPAN);
Metadata metadata1 = mbuiContext.metadataRegistry().lookup(SessionManagement.INFINISPAN.template);
infinispanSessionManagementTable = new ModelNodeTable.Builder<NamedNode>(Ids.build(infinispanId, Ids.TABLE), metadata1)
.button(mbuiContext.tableButtonFactory().add(
SessionManagement.INFINISPAN.template,
table -> presenter.addInfinispanSessionManagement(infinispanId, metadata1)))
.button(mbuiContext.tableButtonFactory().remove(
SessionManagement.INFINISPAN.type,
SessionManagement.INFINISPAN.template,
table -> table.selectedRow().getName(),
() -> presenter.reload()))
.column("name", (cell, type, row, meta) -> row.getName())
.build();
infinispanSessionManagementAffinityElement = new AffinityElement(SessionManagement.INFINISPAN,
mbuiContext.metadataRegistry(), mbuiContext.resources());

Expand Down Expand Up @@ -281,19 +314,6 @@ private Form<NamedNode> createMgmtForm(String mgmtId, SessionManagement sessionM
.build();
}

private Table<NamedNode> createMgmtTable(String mgmtId, SessionManagement sessionManagement) {
Metadata metadata = mbuiContext.metadataRegistry().lookup(sessionManagement.template);
return new ModelNodeTable.Builder<NamedNode>(build(mgmtId, ModelDescriptionConstants.TABLE), metadata)
.button(mbuiContext.tableButtonFactory().add(
build(mgmtId, ModelDescriptionConstants.TABLE, ModelDescriptionConstants.ADD), sessionManagement.type,
sessionManagement.template, (name, address) -> presenter.reload()))
.button(mbuiContext.tableButtonFactory().remove(sessionManagement.type, sessionManagement.template,
table -> table.selectedRow().getName(),
() -> presenter.reload()))
.column("name", (cell, type, row, meta) -> row.getName())
.build();
}

private HTMLElement createMgmtSection(String mgmtId, HTMLElement formElement, HTMLElement affinityElement,
Table<NamedNode> table, SessionManagement sessionManagement) {
Metadata metadata = mbuiContext.metadataRegistry().lookup(sessionManagement.template);
Expand Down

0 comments on commit 3d79245

Please sign in to comment.