public Resource removeResource(final PathAddress requestAddress) {
   final PathAddress address = activeStep.address.append(requestAddress);
   assert isControllingThread();
   Stage currentStage = this.currentStage;
   if (currentStage == null) {
     throw MESSAGES.operationAlreadyComplete();
   }
   if (currentStage != Stage.MODEL) {
     throw MESSAGES.stageAlreadyComplete(Stage.MODEL);
   }
   if (!isModelAffected()) {
     takeWriteLock();
     model = model.clone();
   }
   affectsModel.put(address, NULL);
   Resource model = this.model;
   final Iterator<PathElement> i = address.iterator();
   while (i.hasNext()) {
     final PathElement element = i.next();
     if (element.isMultiTarget()) {
       throw MESSAGES.cannotRemove("*");
     }
     if (!i.hasNext()) {
       model = model.removeChild(element);
     } else {
       model = requireChild(model, element, address);
     }
   }
   return model;
 }
Exemple #2
0
  private static DefaultMutableTreeNode findMatchedChild(
      DefaultMutableTreeNode parent, PathElement pathElement) {

    for (int j = 0; j < parent.getChildCount(); j++) {
      final TreeNode child = parent.getChildAt(j);
      if (!(child instanceof DefaultMutableTreeNode)) continue;
      final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
      final Object userObject = childNode.getUserObject();
      if (pathElement.matchedWithByObject(userObject)) return childNode;
    }

    for (int j = 0; j < parent.getChildCount(); j++) {
      final TreeNode child = parent.getChildAt(j);
      if (!(child instanceof DefaultMutableTreeNode)) continue;
      final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
      final Object userObject = childNode.getUserObject();
      if (!(userObject instanceof NodeDescriptor)) continue;
      final NodeDescriptor nodeDescriptor = (NodeDescriptor) userObject;
      if (pathElement.matchedWith(nodeDescriptor)) return childNode;
    }

    if (parent.getChildCount() > 0) {
      int index = pathElement.myItemIndex;
      if (index >= parent.getChildCount()) {
        index = parent.getChildCount() - 1;
      }
      final TreeNode child = parent.getChildAt(index);
      if (child instanceof DefaultMutableTreeNode) {
        return (DefaultMutableTreeNode) child;
      }
    }

    return null;
  }
Exemple #3
0
 private static void writeExternal(final Element pathXmlElement, final List<PathElement> path)
     throws WriteExternalException {
   for (final PathElement aPath : path) {
     final Element pathXmlElementElement = new Element(PATH_ELEMENT);
     aPath.writeExternal(pathXmlElementElement);
     pathXmlElement.addContent(pathXmlElementElement);
   }
 }
 /** is this path an anchored path? (i.e., does it start with a variable name) */
 public boolean isAnchored() {
   if (pathElements.isEmpty()) {
     return false;
   } else {
     PathElement pe = pathElements.get(0);
     return (pe.isAnchor());
   }
 }
 public void addResource(PathAddress relativeAddress, Resource toAdd) {
   final PathAddress absoluteAddress = activeStep.address.append(relativeAddress);
   assert isControllingThread();
   Stage currentStage = this.currentStage;
   if (currentStage == null) {
     throw MESSAGES.operationAlreadyComplete();
   }
   if (currentStage != Stage.MODEL) {
     throw MESSAGES.stageAlreadyComplete(Stage.MODEL);
   }
   if (absoluteAddress.size() == 0) {
     throw MESSAGES.duplicateResourceAddress(absoluteAddress);
   }
   if (!isModelAffected()) {
     takeWriteLock();
     model = model.clone();
   }
   affectsModel.put(absoluteAddress, NULL);
   Resource model = this.model;
   final Iterator<PathElement> i = absoluteAddress.iterator();
   while (i.hasNext()) {
     final PathElement element = i.next();
     if (element.isMultiTarget()) {
       throw MESSAGES.cannotWriteTo("*");
     }
     if (!i.hasNext()) {
       final String key = element.getKey();
       if (model.hasChild(element)) {
         throw MESSAGES.duplicateResourceAddress(absoluteAddress);
       } else {
         final PathAddress parent = absoluteAddress.subAddress(0, absoluteAddress.size() - 1);
         final Set<String> childrenNames =
             modelController.getRootRegistration().getChildNames(parent);
         if (!childrenNames.contains(key)) {
           throw MESSAGES.noChildType(key);
         }
         model.registerChild(element, toAdd);
         model = toAdd;
       }
     } else {
       model = model.getChild(element);
       if (model == null) {
         PathAddress ancestor = PathAddress.EMPTY_ADDRESS;
         for (PathElement pe : absoluteAddress) {
           ancestor = ancestor.append(pe);
           if (element.equals(pe)) {
             break;
           }
         }
         throw MESSAGES.resourceNotFound(ancestor, absoluteAddress);
       }
     }
   }
 }
Exemple #6
0
 private static List<PathElement> readPath(final Element xmlPathElement)
     throws InvalidDataException {
   final ArrayList<PathElement> result = new ArrayList<PathElement>();
   final List elements = xmlPathElement.getChildren(PATH_ELEMENT);
   for (final Object element : elements) {
     Element xmlPathElementElement = (Element) element;
     final PathElement pathElement = new PathElement();
     pathElement.readExternal(xmlPathElementElement);
     result.add(pathElement);
   }
   return result;
 }
 private static Resource requireChild(
     final Resource resource, final PathElement childPath, final PathAddress fullAddress) {
   if (resource.hasChild(childPath)) {
     return resource.requireChild(childPath);
   } else {
     PathAddress missing = PathAddress.EMPTY_ADDRESS;
     for (PathElement search : fullAddress) {
       missing = missing.append(search);
       if (search.equals(childPath)) {
         break;
       }
     }
     throw ControllerMessages.MESSAGES.managementResourceNotFound(missing);
   }
 }
 public ModelNode readModelForUpdate(final PathAddress requestAddress) {
   final PathAddress address = activeStep.address.append(requestAddress);
   assert isControllingThread();
   Stage currentStage = this.currentStage;
   if (currentStage == null) {
     throw MESSAGES.operationAlreadyComplete();
   }
   if (currentStage != Stage.MODEL) {
     throw MESSAGES.stageAlreadyComplete(Stage.MODEL);
   }
   if (!isModelAffected()) {
     takeWriteLock();
     model = model.clone();
   }
   affectsModel.put(address, NULL);
   Resource model = this.model;
   final Iterator<PathElement> i = address.iterator();
   while (i.hasNext()) {
     final PathElement element = i.next();
     if (element.isMultiTarget()) {
       throw MESSAGES.cannotWriteTo("*");
     }
     if (!i.hasNext()) {
       final String key = element.getKey();
       if (!model.hasChild(element)) {
         final PathAddress parent = address.subAddress(0, address.size() - 1);
         final Set<String> childrenNames =
             modelController.getRootRegistration().getChildNames(parent);
         if (!childrenNames.contains(key)) {
           throw MESSAGES.noChildType(key);
         }
         final Resource newModel = Resource.Factory.create();
         model.registerChild(element, newModel);
         model = newModel;
       } else {
         model = requireChild(model, element, address);
       }
     } else {
       model = requireChild(model, element, address);
     }
   }
   if (model == null) {
     throw new IllegalStateException();
   }
   return model.getModel();
 }
 protected TestModelControllerService(
     final ConfigurationPersister configurationPersister,
     final ControlledProcessState processState) {
   this(
       ProcessType.EMBEDDED_SERVER,
       configurationPersister,
       processState,
       ResourceBuilder.Factory.create(
               PathElement.pathElement("root"), new NonResolvingResourceDescriptionResolver())
           .build());
 }
Exemple #10
0
 public void exec(TreeMapState state) {
   if (exec != null) {
     try {
       List<DataTreeNode> list = exec.processNode(state);
       if (list != null) {
         list.forEach(DataTreeNode::release);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Exemple #11
0
  private static boolean applyTo(
      final int positionInPath,
      final List<PathElement> path,
      final Object root,
      final TreeFacade tree) {
    if (!(root instanceof DefaultMutableTreeNode)) return false;

    final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) root;

    final Object userObject = treeNode.getUserObject();
    final PathElement pathElement = path.get(positionInPath);

    if (userObject instanceof NodeDescriptor) {
      if (!pathElement.matchedWith((NodeDescriptor) userObject)) return false;
    } else {
      if (!pathElement.matchedWithByObject(userObject)) return false;
    }

    tree.expand(treeNode)
        .doWhenDone(
            new Runnable() {
              public void run() {
                if (positionInPath == path.size() - 1) {
                  return;
                }

                for (int j = 0; j < treeNode.getChildCount(); j++) {
                  final TreeNode child = treeNode.getChildAt(j);
                  final boolean resultFromChild = applyTo(positionInPath + 1, path, child, tree);
                  if (resultFromChild) {
                    break;
                  }
                }
              }
            });

    return true;
  }
 @Override
 public void parse(
     final XMLExtendedStreamReader reader, PathAddress parentAddress, List<ModelNode> list)
     throws XMLStreamException {
   if (getXmlWrapperElement() != null) {
     if (reader.getLocalName().equals(getXmlWrapperElement())) {
       if (reader.hasNext()) {
         if (reader.nextTag() == END_ELEMENT) {
           return;
         }
       }
     } else {
       throw ParseUtils.unexpectedElement(reader);
     }
   }
   boolean wildcard = getPathElement().isWildcard();
   String name = null;
   ModelNode op = Util.createAddOperation();
   Map<String, AttributeDefinition> attributes = getAttributeMap();
   for (int i = 0; i < reader.getAttributeCount(); i++) {
     String attributeName = reader.getAttributeLocalName(i);
     String value = reader.getAttributeValue(i);
     if (wildcard && NAME.equals(attributeName)) {
       name = value;
     } else if (attributes.containsKey(attributeName)) {
       AttributeDefinition def = attributes.get(attributeName);
       if (def instanceof SimpleAttributeDefinition) {
         ((SimpleAttributeDefinition) def).parseAndSetParameter(value, op, reader);
       } else if (def instanceof StringListAttributeDefinition) {
         ((StringListAttributeDefinition) def).parseAndSetParameter(value, op, reader);
       } else {
         throw new IllegalArgumentException("we should know how to handle " + def);
       }
     } else {
       throw ParseUtils.unexpectedAttribute(reader, i);
     }
   }
   if (wildcard && name == null) {
     throw MESSAGES.missingRequiredAttributes(new StringBuilder(NAME), reader.getLocation());
   }
   PathElement path =
       wildcard ? PathElement.pathElement(getPathElement().getKey(), name) : getPathElement();
   PathAddress address = parentAddress.append(path);
   op.get(ADDRESS).set(address.toModelNode());
   list.add(op);
   parseChildren(reader, address, list);
   if (getXmlWrapperElement() != null) {
     ParseUtils.requireNoContent(reader);
   }
 }
 public Resource readResourceForUpdate(PathAddress requestAddress) {
   final PathAddress address = activeStep.address.append(requestAddress);
   assert isControllingThread();
   Stage currentStage = this.currentStage;
   if (currentStage == null) {
     throw MESSAGES.operationAlreadyComplete();
   }
   if (currentStage != Stage.MODEL) {
     throw MESSAGES.stageAlreadyComplete(Stage.MODEL);
   }
   if (!isModelAffected()) {
     takeWriteLock();
     model = model.clone();
   }
   affectsModel.put(address, NULL);
   Resource resource = this.model;
   for (PathElement element : address) {
     if (element.isMultiTarget()) {
       throw MESSAGES.cannotWriteTo("*");
     }
     resource = requireChild(resource, element, address);
   }
   return resource;
 }
Exemple #14
0
/**
 * Resource description for the addressable resource
 * /subsystem=infinispan/cache-container=X/cache=Y/loader=LOADER
 *
 * @author Tristan Tarrant
 */
public class LoaderResource extends BaseLoaderResource {

  private static final PathElement LOADER_PATH = PathElement.pathElement(ModelKeys.LOADER);

  // attributes
  static final SimpleAttributeDefinition CLASS =
      new SimpleAttributeDefinitionBuilder(ModelKeys.CLASS, ModelType.STRING, false)
          .setXmlName(Attribute.CLASS.getLocalName())
          .setAllowExpression(true)
          .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
          .build();

  static final AttributeDefinition[] LOADER_ATTRIBUTES = {CLASS};

  static final SimpleAttributeDefinition NAME =
      new SimpleAttributeDefinitionBuilder(BaseStoreResource.NAME)
          .setDefaultValue(new ModelNode().set(ModelKeys.LOADER_NAME))
          .build();

  // operations
  private static final OperationDefinition LOADER_ADD_DEFINITION =
      new SimpleOperationDefinitionBuilder(
              ADD, new InfinispanResourceDescriptionResolver(ModelKeys.LOADER))
          .setParameters(COMMON_LOADER_PARAMETERS)
          .addParameter(CLASS)
          .setAttributeResolver(new InfinispanResourceDescriptionResolver(ModelKeys.LOADER))
          .build();

  public LoaderResource(CacheResource cacheResource) {
    super(LOADER_PATH, ModelKeys.LOADER, cacheResource, LOADER_ATTRIBUTES);
  }

  @Override
  public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
  }

  // override the add operation to provide a custom definition (for the optional PROPERTIES
  // parameter to add())
  @Override
  protected void registerAddOperation(
      final ManagementResourceRegistration registration,
      final OperationStepHandler handler,
      OperationEntry.Flag... flags) {
    registration.registerOperationHandler(LOADER_ADD_DEFINITION, handler);
  }
}
Exemple #15
0
 void setValue(T value) {
   PathElement tail = getLastPathElement();
   tail.setValue(value);
 }
Exemple #16
0
 public Path<T> append(PathElement pe) {
   pe.ownerPath = this;
   if (head == null) head = pe;
   else getLastPathElement().append(pe);
   return this;
 }
Exemple #17
0
 public void resolve(TreeMapper mapper) {
   exec.resolve(mapper);
 }
Exemple #18
0
 public static final PathElement resolvPathElement(String name) {
   return PathElement.valueOf(name.toUpperCase());
 }
Exemple #19
0
 T getValue() {
   PathElement last = getLastPathElement();
   return (T) last.getValue();
 }