@Override public String getFailureDescription() { return context.getLogger().getRejectedResourceWarning(address, operation); } }, OperationResultTransformer.ORIGINAL_RESULT);
private void transformResourceInt(TransformationContext context, PathAddress address, Resource resource) throws OperationFailedException { Set<String> problems = checkModelNode(resource.getModel()); if (problems != null) { if (context.getTarget().isIgnoredResourceListAvailableAtRegistration()) { // Slave is 7.2.x or higher and we know this resource is not ignored List<String> msg = Collections.singletonList(context.getLogger().getAttributeWarning(address, null, problems)); final TransformationTarget tgt = context.getTarget(); final String legacyHostName = tgt.getHostName(); final ModelVersion coreVersion = tgt.getVersion(); final String subsystemName = findSubsystemName(address); final ModelVersion usedVersion = subsystemName == null ? coreVersion : tgt.getSubsystemVersion(subsystemName); // Target is 7.2.x or higher so we should throw an error if (subsystemName != null) { throw ControllerMessages.MESSAGES.rejectAttributesSubsystemModelResourceTransformer(address, legacyHostName, subsystemName, usedVersion, msg); } throw ControllerMessages.MESSAGES.rejectAttributesCoreModelResourceTransformer(address, legacyHostName, usedVersion, msg); } else { // 7.1.x slave; resource *may* be ignored so we can't fail; just log context.getLogger().logAttributeWarning(address, problems); } } }
/** * Get a warning message for the given operation at the provided address for the passed attributes * with a default message appended. Intended for use in providing a failure description for an operation * or an exception message for an {@link OperationFailedException}. * The default appended message is 'Attributes are not understood in the target model version and this resource * will need to be ignored on the target host.' * * @param address where warning occurred * @param operation where which problem occurred * @param attributes attributes we that have problems about */ public String getAttributeWarning(PathAddress address, ModelNode operation, String... attributes) { return getAttributeWarning(address, operation, null, attributes); }
/** * Log a warning for the resource at the provided address and the given attributes. The detail message is a default * 'Attributes are not understood in the target model version and this resource will need to be ignored on the target host.' * * @param address where warning occurred * @param attributes attributes we are warning about */ public void logAttributeWarning(PathAddress address, Set<String> attributes) { logAttributeWarning(address, null, null, attributes); }
@Override public Resource transformResource(final ResourceTransformationContext context, Resource resource) throws OperationFailedException { final ResourceTransformer transformer = target.resolveTransformer(PathAddress.EMPTY_ADDRESS); if (transformer == null) { ControllerLogger.ROOT_LOGGER.tracef("resource %s does not need transformation", resource); return resource; } transformer.transformResource(context, PathAddress.EMPTY_ADDRESS, resource); context.getLogger().flushLogQueue(); return context.getTransformedRoot(); }
public static TransformersLogger getLogger(TransformationTarget target){ String hostName = target.getHostName()==null?"<unknown>":target.getHostName(); TransformersLogger result = loggers.get(hostName); if (result == null) { result = new TransformersLogger(target); TransformersLogger existing = loggers.putIfAbsent(hostName, result); result = existing == null ? result : existing; } return result; }
private ResourceTransformationContextImpl(Resource root, PathAddress address, PathAddress read, final OriginalModel originalModel, TransformerOperationAttachment transformerOperationAttachment, final Transformers.ResourceIgnoredTransformationRegistry ignoredTransformationRegistry) { this.root = root; this.current = address; this.read = read; this.originalModel = originalModel; this.logger = TransformersLogger.getLogger(originalModel.target); this.transformerOperationAttachment = transformerOperationAttachment; this.ignoredTransformationRegistry = ignoredTransformationRegistry; }
@Override public void transformResource(final ResourceTransformationContext ctx, final PathAddress address, final Resource original) throws OperationFailedException { final DiscardPolicy discardPolicy = determineDiscardPolicy(ctx, address); switch (discardPolicy) { case REJECT_AND_WARN: ctx.getLogger().logRejectedResourceWarning(address, null); return; case DISCARD_AND_WARN: // don't return yet, just log a warning first and then discard ctx.getLogger().logDiscardedResourceWarning(address, ctx.getTarget().getHostName()); case SILENT: ResourceTransformer.DISCARD.transformResource(ctx, address, original); return; } final Iterator<TransformationRule> iterator = rules.iterator(); final TransformationRule.ChainedResourceContext context = new TransformationRule.ChainedResourceContext(ctx) { @Override void invokeNext(final Resource resource) throws OperationFailedException { if(iterator.hasNext()) { final TransformationRule next = iterator.next(); next.transformResource(resource, address, this); } else { resourceTransformer.transformResource(ctx, address, resource); } } }; // Kick off the chain final TransformationRule rule = new AttributeTransformationRule(attributeTransformations); rule.transformResource(original, address, context); }
@Override public void transformResource(final ResourceTransformationContext ctx, final PathAddress address, final Resource original) throws OperationFailedException { final ModelNode originalModel = TransformationRule.cloneAndProtect(original.getModel()); // See whether the model can be discarded switch (discardPolicy) { case DISCARD_AND_WARN: case REJECT_AND_WARN: ctx.getLogger().logRejectedResourceWarning(address, null); return; case SILENT: ResourceTransformer.DISCARD.transformResource(ctx, address, original); return; } final Iterator<TransformationRule> iterator = rules.iterator(); final TransformationRule.ChainedResourceContext context = new TransformationRule.ChainedResourceContext(ctx) { @Override void invokeNext(final Resource resource) throws OperationFailedException { if(iterator.hasNext()) { final TransformationRule next = iterator.next(); next.transformResource(resource, address, this); } else { resourceTransformer.transformResource(ctx, address, resource); } } }; // Kick off the chain final TransformationRule rule = new AttributeTransformationRule(attributeTransformations); rule.transformResource(original, address, context); }
private void transformResourceInt(TransformationContext context, PathAddress address, Resource resource) throws OperationFailedException { Set<String> problems = checkModelNode(resource.getModel()); if (problems != null) { if (context.getTarget().isIgnoredResourceListAvailableAtRegistration()) { // Slave is 7.2.x or higher and we know this resource is not ignored List<String> msg = Collections.singletonList(context.getLogger().getAttributeWarning(address, null, problems)); final TransformationTarget tgt = context.getTarget(); final String legacyHostName = tgt.getHostName(); final ModelVersion coreVersion = tgt.getVersion(); final String subsystemName = findSubsystemName(address); final ModelVersion usedVersion = subsystemName == null ? coreVersion : tgt.getSubsystemVersion(subsystemName); // Target is 7.2.x or higher so we should throw an error if (subsystemName != null) { throw ControllerLogger.ROOT_LOGGER.rejectAttributesSubsystemModelResourceTransformer(address, legacyHostName, subsystemName, usedVersion, msg); } throw ControllerLogger.ROOT_LOGGER.rejectAttributesCoreModelResourceTransformer(address, legacyHostName, usedVersion, msg); } else { // 7.1.x slave; resource *may* be ignored so we can't fail; just log context.getLogger().logAttributeWarning(address, problems); } } }
/** * Get a warning message for the given operation at the provided address for the passed attributes * with a default message appended. Intended for use in providing a failure description for an operation * or an exception message for an {@link org.jboss.as.controller.OperationFailedException}. * The default appended message is 'Attributes are not understood in the target model version and this resource * will need to be ignored on the target host.' * * @param address where warning occurred * @param operation where which problem occurred * @param attributes attributes we that have problems about */ public String getAttributeWarning(PathAddress address, ModelNode operation, String... attributes) { return getAttributeWarning(address, operation, null, attributes); }
/** * Log warning for the resource at the provided address and single attribute, using the provided detail * message. * * @param address where warning occurred * @param message custom error message to append * @param attribute attribute we are warning about */ public void logAttributeWarning(PathAddress address, String message, String attribute) { logAttributeWarning(address, null, message, attribute); }
@Override public Resource transformResource(final ResourceTransformationContext context, Resource resource) throws OperationFailedException { final ResourceTransformer transformer = target.resolveTransformer(context, PathAddress.EMPTY_ADDRESS); if (transformer == null) { ControllerLogger.ROOT_LOGGER.tracef("resource %s does not need transformation", resource); return resource; } transformer.transformResource(context, PathAddress.EMPTY_ADDRESS, resource); context.getLogger().flushLogQueue(); return context.getTransformedRoot(); }
public static TransformersLogger getLogger(TransformationTarget target){ String hostName = target.getHostName()==null?"<unknown>":target.getHostName(); TransformersLogger result = loggers.get(hostName); if (result == null) { result = new TransformersLogger(target); TransformersLogger existing = loggers.putIfAbsent(hostName, result); result = existing == null ? result : existing; } return result; }
ResourceTransformationContextImpl(Resource root, PathAddress address, PathAddress read, final OriginalModel originalModel) { this.root = root; this.current = address; this.read = read; this.originalModel = originalModel; this.logger = TransformersLogger.getLogger(originalModel.target); }
@Override public void transformResource(final ResourceTransformationContext ctx, final PathAddress address, final Resource original) throws OperationFailedException { final DiscardPolicy discardPolicy = determineDiscardPolicy(ctx, address); switch (discardPolicy) { case REJECT_AND_WARN: ctx.getLogger().logRejectedResourceWarning(address, null); return; case DISCARD_AND_WARN: // don't return yet, just log a warning first and then discard ctx.getLogger().logDiscardedResourceWarning(address, ctx.getTarget().getHostName()); case SILENT: ResourceTransformer.DISCARD.transformResource(ctx, address, original); return; } final Iterator<TransformationRule> iterator = rules.iterator(); final TransformationRule.ChainedResourceContext context = new TransformationRule.ChainedResourceContext(ctx) { @Override void invokeNext(final Resource resource) throws OperationFailedException { if(iterator.hasNext()) { final TransformationRule next = iterator.next(); next.transformResource(resource, address, this); } else { resourceTransformer.transformResource(ctx, address, resource); } } }; // Kick off the chain final TransformationRule rule = new AttributeTransformationRule(attributeTransformations); rule.transformResource(original, address, context); }
@Override public void transformResource(final ResourceTransformationContext ctx, final PathAddress address, final Resource original) throws OperationFailedException { final ModelNode originalModel = TransformationRule.cloneAndProtect(original.getModel()); // See whether the model can be discarded switch (discardPolicy) { case DISCARD_AND_WARN: case REJECT_AND_WARN: ctx.getLogger().logRejectedResourceWarning(address, null); return; case SILENT: ResourceTransformer.DISCARD.transformResource(ctx, address, original); return; } final Iterator<TransformationRule> iterator = rules.iterator(); final TransformationRule.ChainedResourceContext context = new TransformationRule.ChainedResourceContext(ctx) { @Override void invokeNext(final Resource resource) throws OperationFailedException { if(iterator.hasNext()) { final TransformationRule next = iterator.next(); next.transformResource(resource, address, this); } else { resourceTransformer.transformResource(ctx, address, resource); } } }; // Kick off the chain final TransformationRule rule = new AttributeTransformationRule(attributeTransformations); rule.transformResource(original, address, context); }
private void transformResourceInt(TransformationContext context, PathAddress address, Resource resource) throws OperationFailedException { Set<String> problems = checkModelNode(resource.getModel()); if (problems != null) { if (context.getTarget().isIgnoredResourceListAvailableAtRegistration()) { // Slave is 7.2.x or higher and we know this resource is not ignored List<String> msg = Collections.singletonList(context.getLogger().getAttributeWarning(address, null, problems)); final TransformationTarget tgt = context.getTarget(); final String legacyHostName = tgt.getHostName(); final ModelVersion coreVersion = tgt.getVersion(); final String subsystemName = findSubsystemName(address); final ModelVersion usedVersion = subsystemName == null ? coreVersion : tgt.getSubsystemVersion(subsystemName); // Target is 7.2.x or higher so we should throw an error if (subsystemName != null) { throw ControllerMessages.MESSAGES.rejectAttributesSubsystemModelResourceTransformer(address, legacyHostName, subsystemName, usedVersion, msg); } throw ControllerMessages.MESSAGES.rejectAttributesCoreModelResourceTransformer(address, legacyHostName, usedVersion, msg); } else { // 7.1.x slave; resource *may* be ignored so we can't fail; just log context.getLogger().logAttributeWarning(address, problems); } } }
/** * Get a warning message for the given operation at the provided address for the passed attributes * with a default message appended. Intended for use in providing a failure description for an operation * or an exception message for an {@link org.jboss.as.controller.OperationFailedException}. * The default appended message is 'Attributes are not understood in the target model version and this resource * will need to be ignored on the target host.' * * @param address where warning occurred * @param operation where which problem occurred * @param attributes attributes we that have problems about */ public String getAttributeWarning(PathAddress address, ModelNode operation, String... attributes) { return getAttributeWarning(address, operation, null, attributes); }
/** * Log warning for the resource at the provided address and single attribute, using the provided detail * message. * * @param address where warning occurred * @param message custom error message to append * @param attribute attribute we are warning about */ public void logAttributeWarning(PathAddress address, String message, String attribute) { logAttributeWarning(address, null, message, attribute); }