Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

[HAL-1287] - add capability to display warnings that come from WFCORE… #383

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ResponseProcessorDelegate {

static ResponseProcessor[] processors = {
new DomainResponseProcessor(),
new StandaloneResponseProcessor()
new StandaloneResponseProcessor(),
new WarningProcessor()
};


Expand All @@ -23,15 +24,14 @@ public ResponseProcessorDelegate() {
}

public void process(ModelNode response) {

Map<String, ServerState> serverStates = new HashMap<String, ServerState>();

for(ResponseProcessor proc : processors)
{
if(proc.accepts(response))
{
proc.process(response, serverStates);
break;
//break;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jboss.as.console.client.shared.state;

import java.util.logging.Level;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

public class WarningNotification extends GwtEvent<WarningNotification.Handler> {

public static final Type<WarningNotification.Handler> TYPE = new Type<WarningNotification.Handler>();
private final String warning;
private final Level severity;
public WarningNotification(final String warning, final Level serverity) {
this.warning = warning;
this.severity = serverity;
}

@Override
public Type<Handler> getAssociatedType() {
return TYPE;
}

@Override
protected void dispatch(Handler listener) {
listener.onWarning(this.warning, this.severity);
}

public interface Handler extends EventHandler {
public void onWarning(String warning, Level level);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.jboss.as.console.client.shared.state;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;

import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.Property;
import org.jboss.dmr.client.notify.Notifications;

public class WarningProcessor implements ResponseProcessor {

protected static final String LEVEL = "level";
protected static final String RESPONSE_HEADERS = "response-headers";
protected static final String RESULT = "result";
protected static final String STEP_1 = "step-1";
protected static final String WARNING = "warning";
protected static final String WARNINGS = "warnings";

@Override
public boolean accepts(ModelNode response) {
// result->step-x->response-headers->warnings
if (response.hasDefined(RESULT)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the model node structure the same for both standalone and domain?

Copy link
Contributor Author

@baranowb baranowb Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc yeah, Im going to update this PR since there has been change in core WRT this.
Also, I assume that every op is a "stepped" operation. Not sure if this is correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Steps are usually only used for composite operations. I guess this is also true for this use case. I suggest to talk to Brian, to clarify the exact response structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, but I think console use only composite operation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but that might change - and there might be other operations which cause these response headers. So it would be more robust to be prepared for warnings which are not wrapped inside steps.

final ModelNode result = response.get(RESULT);
if (result.hasDefined(STEP_1)) {
final List<Property> steps = result.asPropertyList();
for (Property step : steps) {
final ModelNode stepContent = step.getValue();
if (stepContent.hasDefined(RESPONSE_HEADERS) && stepContent.get(RESPONSE_HEADERS).hasDefined(WARNINGS)) {
return true;
}
}
}
}
return false;
}

@Override
public void process(ModelNode response, Map<String, ServerState> serverStates) {
final List<ModelNode> warnings = fetchWarnings(response);
for (ModelNode warning : warnings) {
final WarningNotification warningNotification = new WarningNotification(warning.get(WARNING).asString(),
Level.parse(warning.get(LEVEL).asString()));
Notifications.fireWarningNotification(warningNotification);
}
}

protected List<ModelNode> fetchWarnings(final ModelNode response) {
List<ModelNode> warnings = new ArrayList<ModelNode>();
for (Property step : response.get(RESULT).asPropertyList()) {
final ModelNode value = step.getValue();
if (value.hasDefined(RESPONSE_HEADERS) && value.get(RESPONSE_HEADERS).hasDefined(WARNINGS)) {
warnings.addAll(value.get(RESPONSE_HEADERS).get(WARNINGS).asList());
}
}
return warnings;
}

}
11 changes: 11 additions & 0 deletions dmr/src/main/java/org/jboss/dmr/client/notify/Notifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;
import org.jboss.as.console.client.shared.state.ReloadNotification;
import org.jboss.as.console.client.shared.state.WarningNotification;

/**
* @author Heiko Braun
Expand All @@ -18,8 +19,18 @@ public static void addReloadHandler(ReloadNotification.Handler handler)
EVENT_BUS.addHandler(ReloadNotification.TYPE, handler);
}

public static void addWarningHandler(WarningNotification.Handler handler)
{
EVENT_BUS.addHandler(WarningNotification.TYPE, handler);
}

public static void fireReloadNotification(ReloadNotification notification)
{
EVENT_BUS.fireEvent(notification);
}

public static void fireWarningNotification(WarningNotification notification)
{
EVENT_BUS.fireEvent(notification);
}
}
28 changes: 27 additions & 1 deletion gui/src/main/java/org/jboss/as/console/client/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.EnumSet;
import java.util.Map;
import java.util.logging.Level;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.EntryPoint;
Expand Down Expand Up @@ -52,7 +53,9 @@
import org.jboss.as.console.client.shared.state.ReloadNotification;
import org.jboss.as.console.client.shared.state.ReloadState;
import org.jboss.as.console.client.shared.state.ServerState;
import org.jboss.as.console.client.shared.state.WarningNotification;
import org.jboss.as.console.spi.Entrypoint;
import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.dispatch.DispatchError;
import org.jboss.dmr.client.notify.Notifications;
import org.jboss.gwt.circuit.Dispatcher;
Expand All @@ -64,7 +67,7 @@
* @author Heiko Braun
*/
@Entrypoint
public class Console implements EntryPoint, ReloadNotification.Handler {
public class Console implements EntryPoint, ReloadNotification.Handler, WarningNotification.Handler {

public final static UIConstants CONSTANTS = GWT.create(UIConstants.class);
public final static UIDebugConstants DEBUG_CONSTANTS = GWT.create(UIDebugConstants.class);
Expand Down Expand Up @@ -126,6 +129,7 @@ public void onSuccess(BootstrapContext context) {

// DMR notifications
Notifications.addReloadHandler(Console.this);
Notifications.addWarningHandler(Console.this);

/* StringBuilder title = new StringBuilder();
title.append(context.getProductName()).append(" Management");
Expand All @@ -149,6 +153,28 @@ public void onReloadRequired(Map<String, ServerState> states) {
reloadState.propagateChanges();
}

// ------------------------------------------------------ warning handler

public void onWarning(String warning, Level severity){
Message.Severity messsageSeverity = null;
switch(severity.intValue()){
case 1000: //SEVERE
messsageSeverity = messsageSeverity.Error;
break;

case 900: //WARNING
messsageSeverity = messsageSeverity.Warning;
break;

case 800: //INFO
messsageSeverity = messsageSeverity.Info;
break;

default://CONFIG/FINE....
messsageSeverity = messsageSeverity.Info;
}
getMessageCenter().notify(new Message(warning.toString(), messsageSeverity));
}

// ------------------------------------------------------ messages

Expand Down