Skip to content

Commit

Permalink
Merge pull request #1116 from hpehl/JBEAP-26463
Browse files Browse the repository at this point in the history
JBEAP-26463: Split runtime ds presenter/view into xa and non-xa version
  • Loading branch information
hpehl authored Apr 17, 2024
2 parents 4497cda + c6d1f3d commit 7ab48fd
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 80 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/org/jboss/hal/client/ConsoleModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ protected void configure() {
org.jboss.hal.client.runtime.subsystem.datasource.DataSourceView.class,
org.jboss.hal.client.runtime.subsystem.datasource.DataSourcePresenter.MyProxy.class);

bindPresenter(org.jboss.hal.client.runtime.subsystem.datasource.DataSourceXAPresenter.class,
org.jboss.hal.client.runtime.subsystem.datasource.DataSourceXAPresenter.MyView.class,
org.jboss.hal.client.runtime.subsystem.datasource.DataSourceXAView.class,
org.jboss.hal.client.runtime.subsystem.datasource.DataSourceXAPresenter.MyProxy.class);

bindPresenter(org.jboss.hal.client.deployment.DeploymentPresenter.class,
org.jboss.hal.client.deployment.DeploymentPresenter.MyView.class,
org.jboss.hal.client.deployment.DeploymentView.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import static java.util.stream.Collectors.toList;
import static org.jboss.gwt.elemento.core.Elements.span;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.*;
import static org.jboss.hal.client.runtime.subsystem.datasource.DataSourcePresenter.XA_PARAM;
import static org.jboss.hal.core.finder.FinderColumn.RefreshMode.RESTORE_SELECTION;
import static org.jboss.hal.dmr.ModelDescriptionConstants.*;
import static org.jboss.hal.meta.StatementContext.Expression.SELECTED_HOST;
Expand Down Expand Up @@ -277,11 +276,17 @@ public List<ItemAction<DataSource>> actions() {
List<ItemAction<DataSource>> actions = new ArrayList<>();
if (dataSource.isEnabled()) {
if (!dataSource.fromDeployment() && dataSource.isStatisticsEnabled()) {
PlaceRequest placeRequest = places.selectedServer(NameTokens.DATA_SOURCE_RUNTIME)
.with(NAME, dataSource.getName())
.with(XA_PARAM, String.valueOf(dataSource.isXa()))
.build();
actions.add(itemActionFactory.view(placeRequest));
if (dataSource.isXa()) {
PlaceRequest placeRequest = places.selectedServer(NameTokens.DATA_SOURCE_XA_RUNTIME)
.with(NAME, dataSource.getName())
.build();
actions.add(itemActionFactory.view(placeRequest));
} else {
PlaceRequest placeRequest = places.selectedServer(NameTokens.DATA_SOURCE_RUNTIME)
.with(NAME, dataSource.getName())
.build();
actions.add(itemActionFactory.view(placeRequest));
}
}
actions.add(new ItemAction.Builder<DataSource>().title(resources.constants().test())
.handler(item -> testConnection(item))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,16 @@

import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.*;
import static org.jboss.hal.dmr.ModelDescriptionConstants.*;
import static org.jboss.hal.meta.AddressTemplate.OPTIONAL;
import static org.jboss.hal.meta.token.NameTokens.DATA_SOURCE_RUNTIME;

public class DataSourcePresenter
extends ApplicationFinderPresenter<DataSourcePresenter.MyView, DataSourcePresenter.MyProxy> {

static final String XA_PARAM = "xa";

private final FinderPathFactory finderPathFactory;
private final Dispatcher dispatcher;
private final StatementContext statementContext;
private final Resources resources;
private String name;
private boolean xa;

@Inject
public DataSourcePresenter(EventBus eventBus,
Expand Down Expand Up @@ -81,45 +77,37 @@ protected void onBind() {
public void prepareFromRequest(PlaceRequest request) {
super.prepareFromRequest(request);
name = request.getParameter(NAME, null);
xa = Boolean.valueOf(request.getParameter(XA_PARAM, String.valueOf(false)));
getView().setup();
}

@Override
public FinderPath finderPath() {
return finderPathFactory.runtimeServerPath()
.append(Ids.RUNTIME_SUBSYSTEM, DATASOURCES, resources.constants().monitor(), Names.DATASOURCES)
.append(Ids.DATA_SOURCE_RUNTIME, Ids.dataSourceRuntime(name, xa), Names.DATASOURCE, name);
.append(Ids.DATA_SOURCE_RUNTIME, Ids.dataSourceRuntime(name, false), Names.DATASOURCE, name);
}

@Override
protected void reload() {
ResourceAddress address = xa ? XA_DATA_SOURCE_TEMPLATE.resolve(statementContext, name) : DATA_SOURCE_TEMPLATE
.resolve(statementContext, name);
ResourceAddress address = DATA_SOURCE_TEMPLATE.resolve(statementContext, name);
Operation operation = new Operation.Builder(address, READ_RESOURCE_OPERATION)
.param(INCLUDE_RUNTIME, true)
.param(RECURSIVE, true)
.build();
dispatcher.execute(operation, result -> getView().update(new DataSource(name, result, xa)));
dispatcher.execute(operation, result -> getView().update(new DataSource(name, result, false)));
}

String getDataSource() {
return name;
}

boolean isXa() {
return xa;
}


// @formatter:off
@ProxyCodeSplit
@NameToken(DATA_SOURCE_RUNTIME)
@Requires({DATA_SOURCE_ADDRESS, XA_DATA_SOURCE_ADDRESS,
OPTIONAL + DATA_SOURCE_POOL_ADDRESS,
OPTIONAL + DATA_SOURCE_JDBC_ADDRESS,
OPTIONAL + XA_DATA_SOURCE_POOL_ADDRESS,
OPTIONAL + XA_DATA_SOURCE_JDBC_ADDRESS})
DATA_SOURCE_POOL_ADDRESS,
DATA_SOURCE_JDBC_ADDRESS})
public interface MyProxy extends ProxyPlace<DataSourcePresenter> {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import javax.inject.Inject;

import elemental2.dom.HTMLElement;
import org.jboss.gwt.elemento.core.Elements;
import org.jboss.hal.ballroom.Tabs;
import org.jboss.hal.ballroom.form.Form;
import org.jboss.hal.core.datasource.DataSource;
Expand All @@ -41,8 +40,6 @@
import static org.jboss.hal.ballroom.LayoutBuilder.row;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.DATA_SOURCE_JDBC_TEMPLATE;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.DATA_SOURCE_POOL_TEMPLATE;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.XA_DATA_SOURCE_JDBC_TEMPLATE;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.XA_DATA_SOURCE_POOL_TEMPLATE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.STATISTICS_ENABLED;
import static org.jboss.hal.dmr.ModelNodeHelper.failSafeGet;
import static org.jboss.hal.resources.CSS.*;
Expand Down Expand Up @@ -86,74 +83,42 @@ public class DataSourceView extends HalViewImpl implements DataSourcePresenter.M
private final Resources resources;
private DataSourcePresenter presenter;
private HTMLElement header;
private Tabs nonXaTabs;
private Tabs xaTabs;
private Form<ModelNode> poolForm;
private Form<ModelNode> xaPoolForm;
private Form<ModelNode> jdbcForm;
private Form<ModelNode> xaJdbcForm;
private boolean setup;

@Inject
public DataSourceView(MetadataRegistry metadataRegistry, Resources resources) {
this.metadataRegistry = metadataRegistry;
this.resources = resources;
this.setup = false;
}

@Override
public void setup() {
if (setup) {
return;
}

// The metadata for the "statistic" resources is only available fro existing data-sources.
// That's why we cannot setup the UI in the constructor like in other views and
// using wildcards in the address templates. As a workaround we defer the UI setup
// until the DS name is known and replace the wildcards with the DS name.
Metadata poolMeta;
Metadata jdbcMeta;
if (presenter.isXa()) {
poolMeta = metadataRegistry.lookup(
XA_DATA_SOURCE_POOL_TEMPLATE.replaceWildcards(presenter.getDataSource()));
jdbcMeta = metadataRegistry.lookup(
XA_DATA_SOURCE_JDBC_TEMPLATE.replaceWildcards(presenter.getDataSource()));
} else {
poolMeta = metadataRegistry.lookup(DATA_SOURCE_POOL_TEMPLATE.replaceWildcards(presenter.getDataSource()));
jdbcMeta = metadataRegistry.lookup(DATA_SOURCE_JDBC_TEMPLATE.replaceWildcards(presenter.getDataSource()));
}
poolMeta = metadataRegistry.lookup(DATA_SOURCE_POOL_TEMPLATE.replaceWildcards(presenter.getDataSource()));
jdbcMeta = metadataRegistry.lookup(DATA_SOURCE_JDBC_TEMPLATE.replaceWildcards(presenter.getDataSource()));

nonXaTabs = new Tabs(Ids.DATA_SOURCE_RUNTIME_TAB_CONTAINER);
xaTabs = new Tabs(Ids.XA_DATA_SOURCE_RUNTIME_TAB_CONTAINER);
Tabs tabs = new Tabs(Ids.DATA_SOURCE_RUNTIME_TAB_CONTAINER);

poolForm = new ModelNodeForm.Builder<>(Ids.DATA_SOURCE_RUNTIME_POOL_FORM, poolMeta)
.readOnly()
.includeRuntime()
.exclude(STATISTICS_ENABLED)
.exclude(XA_ATTRIBUTES)
.build();
nonXaTabs.add(Ids.DATA_SOURCE_RUNTIME_POOL_TAB, Names.POOL, poolForm.element());

xaPoolForm = new ModelNodeForm.Builder<>(Ids.XA_DATA_SOURCE_RUNTIME_POOL_FORM, poolMeta)
.readOnly()
.includeRuntime()
.exclude(STATISTICS_ENABLED)
.build();
xaTabs.add(Ids.XA_DATA_SOURCE_RUNTIME_POOL_TAB, Names.POOL, xaPoolForm.element());
tabs.add(Ids.DATA_SOURCE_RUNTIME_POOL_TAB, Names.POOL, poolForm.element());

jdbcForm = new ModelNodeForm.Builder<>(Ids.DATA_SOURCE_RUNTIME_JDBC_FORM, jdbcMeta)
.readOnly()
.includeRuntime()
.exclude(STATISTICS_ENABLED)
.build();
nonXaTabs.add(Ids.DATA_SOURCE_RUNTIME_JDBC_TAB, Names.JDBC, jdbcForm.element());

xaJdbcForm = new ModelNodeForm.Builder<>(Ids.XA_DATA_SOURCE_RUNTIME_JDBC_FORM, jdbcMeta)
.readOnly()
.includeRuntime()
.exclude(STATISTICS_ENABLED)
.build();
xaTabs.add(Ids.XA_DATA_SOURCE_RUNTIME_JDBC_TAB, Names.JDBC, xaJdbcForm.element());
tabs.add(Ids.DATA_SOURCE_RUNTIME_JDBC_TAB, Names.JDBC, jdbcForm.element());

HTMLElement root = row()
.add(column()
Expand All @@ -162,12 +127,11 @@ public void setup() {
.add(a().css(clickable, pullRight).on(click, event -> refresh())
.add(span().css(fontAwesome("refresh"), marginRight5))
.add(span().textContent(resources.constants().refresh()))))
.add(nonXaTabs)
.add(xaTabs)).element();
.add(tabs))
.element();

registerAttachables(asList(poolForm, xaPoolForm, jdbcForm, xaJdbcForm));
registerAttachables(asList(poolForm, jdbcForm));
initElement(root);
setup = true;
}

@Override
Expand All @@ -177,20 +141,9 @@ public void setPresenter(DataSourcePresenter presenter) {

@Override
public void update(DataSource dataSource) {
showHide(dataSource.isXa());
header.textContent = dataSource.getName();
if (dataSource.isXa()) {
xaPoolForm.view(failSafeGet(dataSource, POOL_PATH));
xaJdbcForm.view(failSafeGet(dataSource, JDBC_PATH));
} else {
poolForm.view(failSafeGet(dataSource, POOL_PATH));
jdbcForm.view(failSafeGet(dataSource, JDBC_PATH));
}
}

private void showHide(boolean xa) {
Elements.setVisible(nonXaTabs.element(), !xa);
Elements.setVisible(xaTabs.element(), xa);
poolForm.view(failSafeGet(dataSource, POOL_PATH));
jdbcForm.view(failSafeGet(dataSource, JDBC_PATH));
}

private void refresh() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright 2022 Red Hat
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.hal.client.runtime.subsystem.datasource;

import javax.inject.Inject;
import org.jboss.hal.core.datasource.DataSource;
import org.jboss.hal.core.finder.Finder;
import org.jboss.hal.core.finder.FinderPath;
import org.jboss.hal.core.finder.FinderPathFactory;
import org.jboss.hal.core.mvp.ApplicationFinderPresenter;
import org.jboss.hal.core.mvp.HalView;
import org.jboss.hal.core.mvp.HasPresenter;
import org.jboss.hal.dmr.Operation;
import org.jboss.hal.dmr.ResourceAddress;
import org.jboss.hal.dmr.dispatch.Dispatcher;
import org.jboss.hal.meta.StatementContext;
import org.jboss.hal.resources.Ids;
import org.jboss.hal.resources.Names;
import org.jboss.hal.resources.Resources;
import org.jboss.hal.spi.Requires;
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 com.gwtplatform.mvp.shared.proxy.PlaceRequest;

import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.DATA_SOURCE_ADDRESS;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.XA_DATA_SOURCE_ADDRESS;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.XA_DATA_SOURCE_JDBC_ADDRESS;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.XA_DATA_SOURCE_POOL_ADDRESS;
import static org.jboss.hal.client.runtime.subsystem.datasource.AddressTemplates.XA_DATA_SOURCE_TEMPLATE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.DATASOURCES;
import static org.jboss.hal.dmr.ModelDescriptionConstants.INCLUDE_RUNTIME;
import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
import static org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION;
import static org.jboss.hal.dmr.ModelDescriptionConstants.RECURSIVE;
import static org.jboss.hal.meta.token.NameTokens.DATA_SOURCE_XA_RUNTIME;

public class DataSourceXAPresenter
extends ApplicationFinderPresenter<DataSourceXAPresenter.MyView, DataSourceXAPresenter.MyProxy> {

private final FinderPathFactory finderPathFactory;
private final Dispatcher dispatcher;
private final StatementContext statementContext;
private final Resources resources;
private String name;

@Inject
public DataSourceXAPresenter(EventBus eventBus,
MyView view,
MyProxy myProxy,
Finder finder,
FinderPathFactory finderPathFactory,
Dispatcher dispatcher,
StatementContext statementContext,
Resources resources) {
super(eventBus, view, myProxy, finder);
this.finderPathFactory = finderPathFactory;
this.dispatcher = dispatcher;
this.statementContext = statementContext;
this.resources = resources;
}

@Override
protected void onBind() {
super.onBind();
getView().setPresenter(this);
}

@Override
public void prepareFromRequest(PlaceRequest request) {
super.prepareFromRequest(request);
name = request.getParameter(NAME, null);
getView().setup();
}

@Override
public FinderPath finderPath() {
return finderPathFactory.runtimeServerPath()
.append(Ids.RUNTIME_SUBSYSTEM, DATASOURCES, resources.constants().monitor(), Names.DATASOURCES)
.append(Ids.DATA_SOURCE_RUNTIME, Ids.dataSourceRuntime(name, true), Names.DATASOURCE, name);
}

@Override
protected void reload() {
ResourceAddress address = XA_DATA_SOURCE_TEMPLATE.resolve(statementContext, name);
Operation operation = new Operation.Builder(address, READ_RESOURCE_OPERATION)
.param(INCLUDE_RUNTIME, true)
.param(RECURSIVE, true)
.build();
dispatcher.execute(operation, result -> getView().update(new DataSource(name, result, true)));
}

String getDataSource() {
return name;
}

// @formatter:off
@ProxyCodeSplit
@NameToken(DATA_SOURCE_XA_RUNTIME)
@Requires({ DATA_SOURCE_ADDRESS, XA_DATA_SOURCE_ADDRESS,
XA_DATA_SOURCE_POOL_ADDRESS,
XA_DATA_SOURCE_JDBC_ADDRESS })
public interface MyProxy extends ProxyPlace<DataSourceXAPresenter> {
}

public interface MyView extends HalView, HasPresenter<DataSourceXAPresenter> {
void setup();

void update(DataSource dataSource);
}
// @formatter:on
}
Loading

0 comments on commit 7ab48fd

Please sign in to comment.