Skip to content

Commit

Permalink
Log deprecation warnings when properties are added/removed/updated/re…
Browse files Browse the repository at this point in the history
…ad via the deprecated property resource.
  • Loading branch information
pferraro committed May 31, 2017
1 parent 179d642 commit 3422b49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Expand Up @@ -36,6 +36,7 @@
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.logging.ControllerLogger;
import org.jboss.as.controller.operations.global.MapOperations;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
Expand Down Expand Up @@ -80,6 +81,7 @@ public void register(ManagementResourceRegistration parentRegistration) {
AbstractAddStepHandler addHandler = new AbstractAddStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
context.createResource(PathAddress.EMPTY_ADDRESS);
String name = context.getCurrentAddressValue();
String value = operation.get(VALUE.getName()).asString();
Expand All @@ -93,6 +95,7 @@ public void execute(OperationContext context, ModelNode operation) {
AbstractRemoveStepHandler removeHandler = new AbstractRemoveStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
context.removeResource(PathAddress.EMPTY_ADDRESS);
String name = context.getCurrentAddressValue();
PathAddress storeAddress = context.getCurrentAddress().getParent();
Expand All @@ -105,22 +108,28 @@ public void execute(OperationContext context, ModelNode operation) {
OperationStepHandler readHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress().getParent();
operationDeprecated(context, operation);
PathAddress storeAddress = context.getCurrentAddress().getParent();
String key = context.getCurrentAddressValue();
ModelNode getOperation = Operations.createMapGetOperation(address, StoreResourceDefinition.Attribute.PROPERTIES, key);
ModelNode getOperation = Operations.createMapGetOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, key);
context.addStep(getOperation, MapOperations.MAP_GET_HANDLER, context.getCurrentStage());
}
};
OperationStepHandler writeHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress().getParent();
operationDeprecated(context, operation);
PathAddress storeAddress = context.getCurrentAddress().getParent();
String key = context.getCurrentAddressValue();
String value = Operations.getAttributeValue(operation).asString();
ModelNode putOperation = Operations.createMapPutOperation(address, StoreResourceDefinition.Attribute.PROPERTIES, key, value);
ModelNode putOperation = Operations.createMapPutOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, key, value);
context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
}
};
registration.registerReadWriteAttribute(VALUE, readHandler, writeHandler);
}

static void operationDeprecated(OperationContext context, ModelNode operation) {
ControllerLogger.DEPRECATED_LOGGER.operationDeprecated(Operations.getName(operation), context.getCurrentAddress().toCLIStyleString());
}
}
Expand Up @@ -42,6 +42,7 @@
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.logging.ControllerLogger;
import org.jboss.as.controller.operations.global.MapOperations;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
Expand Down Expand Up @@ -107,11 +108,12 @@ public void register(ManagementResourceRegistration parentRegistration) {
AbstractAddStepHandler addHandler = new AbstractAddStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
this.createResource(context);
String name = context.getCurrentAddressValue();
String value = operation.get(VALUE.getName()).asString();
PathAddress storeAddress = context.getCurrentAddress().getParent();
ModelNode putOperation = Operations.createMapPutOperation(storeAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, name, value);
PathAddress protocolAddress = context.getCurrentAddress().getParent();
ModelNode putOperation = Operations.createMapPutOperation(protocolAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, name, value);
context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
}
};
Expand All @@ -121,10 +123,11 @@ public void execute(OperationContext context, ModelNode operation) {
AbstractRemoveStepHandler removeHandler = new AbstractRemoveStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
context.removeResource(PathAddress.EMPTY_ADDRESS);
String name = context.getCurrentAddressValue();
PathAddress storeAddress = context.getCurrentAddress().getParent();
ModelNode putOperation = Operations.createMapRemoveOperation(storeAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, name);
PathAddress protocolAddress = context.getCurrentAddress().getParent();
ModelNode putOperation = Operations.createMapRemoveOperation(protocolAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, name);
context.addStep(putOperation, MapOperations.MAP_REMOVE_HANDLER, context.getCurrentStage());
}
};
Expand All @@ -134,24 +137,29 @@ public void execute(OperationContext context, ModelNode operation) {
OperationStepHandler readHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress().getParent();
operationDeprecated(context, operation);
PathAddress protocolAddress = context.getCurrentAddress().getParent();
String key = context.getCurrentAddressValue();
ModelNode getOperation = Operations.createMapGetOperation(address, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, key);
ModelNode getOperation = Operations.createMapGetOperation(protocolAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, key);
context.addStep(getOperation, MapOperations.MAP_GET_HANDLER, context.getCurrentStage());
}
};
// Delegate write of property value to "properties" attribute of parent protocol
OperationStepHandler writeHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress().getParent();
operationDeprecated(context, operation);
PathAddress protocolAddress = context.getCurrentAddress().getParent();
String key = context.getCurrentAddressValue();
String value = Operations.getAttributeValue(operation).asString();
ModelNode putOperation = Operations.createMapPutOperation(address, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, key, value);
ModelNode putOperation = Operations.createMapPutOperation(protocolAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, key, value);
context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
}
};
registration.registerReadWriteAttribute(VALUE, readHandler, writeHandler);
}

static void operationDeprecated(OperationContext context, ModelNode operation) {
ControllerLogger.DEPRECATED_LOGGER.operationDeprecated(Operations.getName(operation), context.getCurrentAddress().toCLIStyleString());
}
}

0 comments on commit 3422b49

Please sign in to comment.