Java Code Examples for org.jboss.dmr.ModelType#LIST
The following examples show how to use
org.jboss.dmr.ModelType#LIST .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IOpenShiftImageTagger.java From jenkins-plugin with Apache License 2.0 | 6 votes |
default String deriveImageTag(String imageID, IImageStream srcIS) { // TODO port to ImageStream.java in openshift-restclient-java ModelNode imageStream = ((ImageStream) srcIS).getNode(); ModelNode status = imageStream.get("status"); ModelNode tags = status.get("tags"); if (tags.getType() != ModelType.LIST) return null; List<ModelNode> tagWrappers = tags.asList(); for (ModelNode tagWrapper : tagWrappers) { ModelNode tag = tagWrapper.get("tag"); ModelNode items = tagWrapper.get("items"); for (ModelNode itemWrapper : items.asList()) { ModelNode image = itemWrapper.get("image"); if (image != null && (image.asString().equals(imageID) || image .asString().substring(7).equals(imageID))) { return tag.asString(); } } } return null; }
Example 2
Source File: ServerOperations.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
/** * Finds the parent address, everything before the last address part. * * @param address the address to get the parent * * @return the parent address * * @throws IllegalArgumentException if the address is not of type {@link ModelType#LIST} or is empty */ public static ModelNode getParentAddress(final ModelNode address) { if (address.getType() != ModelType.LIST) { throw new IllegalArgumentException("The address type must be a list."); } final ModelNode result = new ModelNode(); final List<Property> addressParts = address.asPropertyList(); if (addressParts.isEmpty()) { throw new IllegalArgumentException("The address is empty."); } for (int i = 0; i < addressParts.size() - 1; ++i) { final Property property = addressParts.get(i); result.add(property.getName(), property.getValue()); } return result; }
Example 3
Source File: HelpSupport.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static String buildOperationArgumentType(ModelNode p) { StringBuilder builder = new StringBuilder(); ModelType mt = getAdaptedArgumentType(p); boolean isList = mt == ModelType.LIST; builder.append(mt); boolean isObject = false; if (isList) { String t = null; if (p.hasDefined(Util.VALUE_TYPE)) { ModelNode vt = p.get(Util.VALUE_TYPE); isObject = isObject(vt); } if (isObject) { t = "OBJECT"; } else { t = p.get(Util.VALUE_TYPE).asType().name(); } builder.append(" of ").append(t); } return builder.toString(); }
Example 4
Source File: PrimitiveListAttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
static ModelNode parseSingleElementToList(AttributeDefinition ad, ModelNode original, ModelNode resolved) { ModelNode result = resolved; if (original.isDefined() && !resolved.equals(original) && resolved.getType() == ModelType.LIST && resolved.asInt() == 1) { // WFCORE-3448. We have a list with 1 element that is not the same as the defined original. // So that implies we had an expression as the element, which is what we would have gotten // if the expression string was passed by an xml parser to parseAndSetParameter. See if the // resolved form of that expression in turn parses to a list and if it does, used the parsed list. ModelNode element = resolved.get(0); if (element.getType() == ModelType.STRING) { ModelNode holder = new ModelNode(); try { ad.getParser().parseAndSetParameter(ad, element.asString(), holder, null); ModelNode parsed = holder.get(ad.getName()); if (parsed.getType() == ModelType.LIST && parsed.asInt() > 1) { result = parsed; } } catch (XMLStreamException | RuntimeException e) { // ignore and just return the original value } } } return result; }
Example 5
Source File: ModelTestUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Scans for entries of type STRING containing expression formatted strings. This is to trap where parsers * call ModelNode.set("${A}") when ModelNode.setExpression("${A}) should have been used * * @param model the model to check */ public static void scanForExpressionFormattedStrings(ModelNode model) { if (model.getType().equals(ModelType.STRING)) { if (EXPRESSION_PATTERN.matcher(model.asString()).matches()) { Assert.fail("ModelNode with type==STRING contains an expression formatted string: " + model.asString()); } } else if (model.getType() == ModelType.OBJECT) { for (String key : model.keys()) { final ModelNode child = model.get(key); scanForExpressionFormattedStrings(child); } } else if (model.getType() == ModelType.LIST) { List<ModelNode> list = model.asList(); for (ModelNode entry : list) { scanForExpressionFormattedStrings(entry); } } else if (model.getType() == ModelType.PROPERTY) { Property prop = model.asProperty(); scanForExpressionFormattedStrings(prop.getValue()); } }
Example 6
Source File: HelpSupport.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static String buildOperationArgumentDescription(ModelNode p) { StringBuilder builder = new StringBuilder(); builder.append(buildOperationArgumentType(p)).append(", "); builder.append(p.get(Util.DESCRIPTION).asString()); if (p.hasDefined(Util.VALUE_TYPE)) { boolean isList = p.get(Util.TYPE).asType() == ModelType.LIST; if (isList) { builder.append(" List items are "); } ModelNode vt = p.get(Util.VALUE_TYPE); if (isObject(vt)) { if (isList) { builder.append("OBJECT instances with the following properties:"). append(Config.getLineSeparator()); } else { builder.append("OBJECT properties:").append(Config.getLineSeparator()); } for (String prop : vt.keys()) { ModelNode mn = vt.get(prop); builder.append(Config.getLineSeparator()).append("- "). append(prop).append(": "). append(buildOperationArgumentType(mn)).append(", "). append(getAdaptedArgumentDescription(mn)); builder.append(Config.getLineSeparator()); } } else { builder.append(vt.asType()); } } return builder.toString(); }
Example 7
Source File: OperationValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void checkList(final ModelNode operation, final String paramName, final ModelNode describedProperty, final ModelNode value) { if (describedProperty.get(TYPE).asType() == ModelType.LIST) { if (describedProperty.hasDefined(VALUE_TYPE) && describedProperty.get(VALUE_TYPE).getType() == ModelType.TYPE) { ModelType elementType = describedProperty.get(VALUE_TYPE).asType(); for (ModelNode element : value.asList()) { try { checkType(elementType, element); } catch (IllegalArgumentException e) { throw ControllerLogger.ROOT_LOGGER.validationFailedInvalidElementType(paramName, elementType, formatOperationForMessage(operation)); } } } } }
Example 8
Source File: SubsystemOperations.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Reads the result of an operation and returns the result as a list of strings. If the operation does not have a * {@link org.jboss.as.controller.client.helpers.ClientConstants#RESULT} attribute and empty list is returned. * * @param result the result of executing an operation * * @return the result of the operation or an empty list */ public static List<String> readResultAsList(final ModelNode result) { if (result.hasDefined(RESULT) && result.get(RESULT).getType() == ModelType.LIST) { final List<String> list = new ArrayList<String>(); for (ModelNode n : result.get(RESULT).asList()) list.add(n.asString()); return list; } return Collections.emptyList(); }
Example 9
Source File: ServerOperations.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 5 votes |
/** * Finds the last entry of the address list and returns it as a property. * * @param address the address to get the last part of * * @return the last part of the address * * @throws IllegalArgumentException if the address is not of type {@link ModelType#LIST} or is empty */ public static Property getChildAddress(final ModelNode address) { if (address.getType() != ModelType.LIST) { throw new IllegalArgumentException("The address type must be a list."); } final List<Property> addressParts = address.asPropertyList(); if (addressParts.isEmpty()) { throw new IllegalArgumentException("The address is empty."); } return addressParts.get(addressParts.size() - 1); }
Example 10
Source File: ModelParserUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void compare(ModelNode node1, ModelNode node2) { Assert.assertEquals(node1.getType(), node2.getType()); if (node1.getType() == ModelType.OBJECT) { final Set<String> keys1 = node1.keys(); final Set<String> keys2 = node2.keys(); Assert.assertEquals(node1 + "\n" + node2, keys1.size(), keys2.size()); for (String key : keys1) { final ModelNode child1 = node1.get(key); Assert.assertTrue("Missing: " + key + "\n" + node1 + "\n" + node2, node2.has(key)); final ModelNode child2 = node2.get(key); if (child1.isDefined()) { Assert.assertTrue(child1.toString(), child2.isDefined()); compare(child1, child2); } else { Assert.assertFalse(child2.asString(), child2.isDefined()); } } } else if (node1.getType() == ModelType.LIST) { List<ModelNode> list1 = node1.asList(); List<ModelNode> list2 = node2.asList(); Assert.assertEquals(list1 + "\n" + list2, list1.size(), list2.size()); for (int i = 0; i < list1.size(); i++) { compare(list1.get(i), list2.get(i)); } } else if (node1.getType() == ModelType.PROPERTY) { Property prop1 = node1.asProperty(); Property prop2 = node2.asProperty(); Assert.assertEquals(prop1 + "\n" + prop2, prop1.getName(), prop2.getName()); compare(prop1.getValue(), prop2.getValue()); } else { Assert.assertEquals("\n\"" + node1.asString() + "\"\n\"" + node2.asString() + "\"\n-----", node1.asString().trim(), node2.asString().trim()); } }
Example 11
Source File: AbstractLoggingSubsystemTest.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static List<String> modelNodeAsStringList(final ModelNode node) { if (node.getType() == ModelType.LIST) { final List<String> result = new ArrayList<>(); for (ModelNode n : node.asList()) result.add(n.asString()); return result; } return Collections.emptyList(); }
Example 12
Source File: ParsedInterfaceCriteria.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static InterfaceCriteria parseNested(final ModelNode subModel, final boolean any, final ExpressionResolver expressionResolver) throws OperationFailedException { if(!subModel.isDefined() || subModel.asInt() == 0) { return null; } final Set<InterfaceCriteria> criteriaSet = new LinkedHashSet<InterfaceCriteria>(); for(final Property nestedProperty : subModel.asPropertyList()) { final Element element = Element.forName(nestedProperty.getName()); switch (element) { case INET_ADDRESS: case NIC : case NIC_MATCH: case SUBNET_MATCH: { if (nestedProperty.getValue().getType() == ModelType.LIST) { for (ModelNode item : nestedProperty.getValue().asList()) { Property prop = new Property(nestedProperty.getName(), item); InterfaceCriteria itemCriteria = parseCriteria(prop, true, expressionResolver); if(itemCriteria != null) { criteriaSet.add(itemCriteria); } } break; } // else drop down into default: block } default: { final InterfaceCriteria criteria = parseCriteria(nestedProperty, true, expressionResolver); if(criteria != null) { criteriaSet.add(criteria); } } } } if(criteriaSet.isEmpty()) { return null; } return any ? new AnyInterfaceCriteria(criteriaSet) : new NotInterfaceCriteria(criteriaSet); }
Example 13
Source File: IOpenShiftImageTagger.java From jenkins-plugin with Apache License 2.0 | 5 votes |
default String deriveImageID(String srcTag, IImageStream srcIS) { String srcImageID = srcIS.getImageId(srcTag); if (srcImageID != null && srcImageID.length() > 0) { // srcTag an valid ImageStreamTag, so translating to an // ImageStreamImage srcImageID = srcIS.getName() + "@" + (srcImageID.startsWith("sha256:") ? srcImageID .substring(7) : srcImageID); return srcImageID; } else { // not a valid ImageStreamTag, see if a valid ImageStreamImage // TODO port to ImageStream.java in openshift-restclient-java ModelNode imageStream = ((ImageStream) srcIS).getNode(); ModelNode status = imageStream.get("status"); ModelNode tags = status.get("tags"); if (tags.getType() != ModelType.LIST) return null; List<ModelNode> tagWrappers = tags.asList(); for (ModelNode tagWrapper : tagWrappers) { ModelNode tag = tagWrapper.get("tag"); ModelNode items = tagWrapper.get("items"); for (ModelNode itemWrapper : items.asList()) { ModelNode image = itemWrapper.get("image"); if (image != null && (image.asString().equals(srcTag) || image .asString().substring(7).equals(srcTag))) { return srcIS.getName() + "@" + (srcTag.startsWith("sha256:") ? srcTag .substring(7) : srcTag); } } } } return null; }
Example 14
Source File: AnalysisContext.java From revapi with Apache License 2.0 | 4 votes |
private ModelNode convertToNewStyle(ModelNode configuration) { if (configuration.getType() == ModelType.LIST) { Map<String, Set<String>> idsByExtension = new HashMap<>(4); for (ModelNode c : configuration.asList()) { if (c.hasDefined("id")) { String extension = c.get("extension").asString(); String id = c.get("id").asString(); boolean added = idsByExtension.computeIfAbsent(extension, x -> new HashSet<>(2)).add(id); if (!added) { throw new IllegalArgumentException( "A configuration cannot contain 2 extension configurations with the same id. " + "At least 2 extension configurations of extension '" + extension + "' have the id '" + id + "'."); } } } return configuration; } if (knownExtensionIds == null) { throw new IllegalArgumentException( "The analysis context builder wasn't supplied with the list of known extension ids," + " so it only can process new-style configurations."); } ModelNode newStyleConfig = new ModelNode(); newStyleConfig.setEmptyList(); extensionScan: for (String extensionId : knownExtensionIds) { String[] explodedId = extensionId.split("\\."); ModelNode extConfig = configuration; for (String segment : explodedId) { if (!extConfig.hasDefined(segment)) { continue extensionScan; } else { extConfig = extConfig.get(segment); } } ModelNode extNewStyle = new ModelNode(); extNewStyle.get("extension").set(extensionId); extNewStyle.get("configuration").set(extConfig); newStyleConfig.add(extNewStyle); } return newStyleConfig; }
Example 15
Source File: MBeanInfoFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private OpenMBeanParameterInfo[] getParameterInfos(ModelNode opNode) { if (!opNode.hasDefined(REQUEST_PROPERTIES)) { return EMPTY_PARAMETERS; } List<Property> propertyList = opNode.get(REQUEST_PROPERTIES).asPropertyList(); List<OpenMBeanParameterInfo> params = new ArrayList<OpenMBeanParameterInfo>(propertyList.size()); for (Property prop : propertyList) { ModelNode value = prop.getValue(); String paramName = NameConverter.convertToCamelCase(prop.getName()); Map<String, Object> descriptions = new HashMap<String, Object>(4); boolean expressionsAllowed = prop.getValue().hasDefined(EXPRESSIONS_ALLOWED) && prop.getValue().get(EXPRESSIONS_ALLOWED).asBoolean(); descriptions.put(DESC_EXPRESSIONS_ALLOWED, String.valueOf(expressionsAllowed)); if (!expressionsAllowed) { Object defaultValue = getIfExists(value, DEFAULT); descriptions.put(DEFAULT_VALUE_FIELD, defaultValue); if (value.has(ALLOWED)) { if (value.get(TYPE).asType()!=ModelType.LIST){ List<ModelNode> allowed = value.get(ALLOWED).asList(); descriptions.put(LEGAL_VALUES_FIELD, fromModelNodes(allowed)); } } else { if (value.has(MIN)) { Comparable minC = getIfExistsAsComparable(value, MIN); if (minC instanceof Number) { descriptions.put(MIN_VALUE_FIELD, minC); } } if (value.has(MAX)) { Comparable maxC = getIfExistsAsComparable(value, MAX); if (maxC instanceof Number) { descriptions.put(MAX_VALUE_FIELD, maxC); } } } } params.add( new OpenMBeanParameterInfoSupport( paramName, getDescription(prop.getValue()), converters.convertToMBeanType(value), new ImmutableDescriptor(descriptions))); } return params.toArray(new OpenMBeanParameterInfo[params.size()]); }
Example 16
Source File: DeploymentItemCompleter.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void getCandidates(CommandContext ctx, String buffer, List<String> candidates) { try { // Corner case "." if (buffer.equals(".")) { candidates.add("./"); return; } // Root dir of file system, meaningless. if (buffer.equals("/")) { return; } String[] parsed = parsePath(buffer); String directory = parsed[0]; String subpath = parsed[1]; DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(address); builder.setOperationName(Util.BROWSE_CONTENT); builder.addProperty(Util.PATH, directory); builder.addProperty(Util.DEPTH, "1"); ModelNode mn = builder.buildRequest(); ModelNode response = ctx.getModelControllerClient().execute(mn); if (response.hasDefined(Util.OUTCOME) && response.get(Util.OUTCOME). asString().equals(Util.SUCCESS)) { ModelNode result = response.get(Util.RESULT); if (result.getType() == ModelType.LIST) { for (int i = 0; i < result.asInt(); i++) { String path = result.get(i).get(Util.PATH).asString(); if (path.startsWith(subpath) && !path.equals(subpath)) { candidates.add(path); } } } } else { log.debug("Invalid response getting candidates"); } } catch (OperationFormatException | IOException ex) { log.debug("Exception getting candidates", ex); } }
Example 17
Source File: ResourceCompositeOperationHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
protected Map<String, ArgumentWithValue> getOperationArguments(CommandContext ctx, String opName) throws CommandLineException { Map<String, ArgumentWithValue> args = opArgs.get(opName); if(args != null) { return args; } final ModelNode descr = getOperationDescription(ctx, opName); if(descr.has(Util.REQUEST_PROPERTIES)) { args = new HashMap<String,ArgumentWithValue>(); final List<Property> propList = descr.get(Util.REQUEST_PROPERTIES).asPropertyList(); for (Property prop : propList) { CommandLineCompleter valueCompleter = null; ArgumentValueConverter valueConverter = null; if(propConverters != null) { valueConverter = propConverters.get(prop.getName()); } if(valueCompleters != null) { valueCompleter = valueCompleters.get(prop.getName()); } if(valueConverter == null) { valueConverter = ArgumentValueConverter.DEFAULT; final ModelType propType = getType(prop.getValue()); if(propType != null) { if(ModelType.BOOLEAN == propType) { if(valueCompleter == null) { valueCompleter = SimpleTabCompleter.BOOLEAN; } } else if(ModelType.STRING == propType) { valueConverter = ArgumentValueConverter.NON_OBJECT; } else if(prop.getName().endsWith("properties")) { // TODO this is bad but can't rely on proper descriptions valueConverter = ArgumentValueConverter.PROPERTIES; } else if(ModelType.LIST == propType) { if(asType(descr.get(Util.VALUE_TYPE)) == ModelType.PROPERTY) { valueConverter = ArgumentValueConverter.PROPERTIES; } else { valueConverter = ArgumentValueConverter.LIST; } } } } final ArgumentWithValue arg = new ArgumentWithValue(ResourceCompositeOperationHandler.this, valueCompleter, valueConverter, "--" + prop.getName()); args.put(arg.getFullName(), arg); } } else { args = Collections.emptyMap(); } opArgs.put(opName, args); return args; }
Example 18
Source File: ListAttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
protected Builder(String attributeName, boolean optional) { super(attributeName, ModelType.LIST, optional); this.setAttributeParser(AttributeParser.STRING_LIST); }
Example 19
Source File: DMRDriver.java From hawkular-agent with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Map<DMRNodeLocation, ModelNode> fetchNodes(DMRNodeLocation query) throws ProtocolException { ReadResourceOperationBuilder<?> opBuilder = OperationBuilder .readResource()// .address(query.getPathAddress()) // .includeRuntime(); // time the execute separately - we want to time ONLY the execute call OperationResult<?> opResult; try (Context timerContext = diagnostics.getRequestTimer().time()) { opResult = opBuilder.execute(client); } catch (Exception e) { diagnostics.getErrorRate().mark(1); throw new ProtocolException("Error fetching nodes for query [" + query + "]", e); } Optional<ModelNode> resultNode = opResult.getOptionalResultNode(); if (resultNode.isPresent()) { ModelNode n = resultNode.get(); if (n.getType() == ModelType.OBJECT) { return Collections.singletonMap(query, n); } else if (n.getType() == ModelType.LIST) { Map<DMRNodeLocation, ModelNode> result = new HashMap<>(); List<ModelNode> list = n.asList(); for (ModelNode item : list) { ModelNode pathAddress = item.get(JBossASClient.ADDRESS); pathAddress = makePathAddressFullyQualified_WFLY6628(query.getPathAddress(), pathAddress); result.put(DMRNodeLocation.of(pathAddress, true, true), JBossASClient.getResults(item)); } return Collections.unmodifiableMap(result); } else { throw new IllegalStateException("Invalid type - please report this bug: " + n.getType() + " [[" + n.toString() + "]]"); } } else { return Collections.emptyMap(); } }
Example 20
Source File: Operations.java From wildfly-core with GNU Lesser General Public License v2.1 | 3 votes |
/** * Creates an operation. * * @param operation the operation name * @param address the address for the operation * * @return the operation * * @throws IllegalArgumentException if the address is not of type {@link org.jboss.dmr.ModelType#LIST} */ public static ModelNode createOperation(final String operation, final ModelNode address) { if (address.getType() != ModelType.LIST) { throw ControllerClientLogger.ROOT_LOGGER.invalidAddressType(); } final ModelNode op = createOperation(operation); op.get(OP_ADDR).set(address); return op; }