/** {@inheritDoc} */ @Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // log.info("Populating the model"); model.setEmptyObject(); model.get(ModelKeys.MAIL_SESSION); }
void updatePoolService(final OperationContext context, final ModelNode model) throws OperationFailedException { final ModelNode poolName = poolAttribute.resolveModelAttribute(context, model); final ServiceRegistry serviceRegistry = context.getServiceRegistry(true); ServiceController existingDefaultPoolConfigService = serviceRegistry.getService(poolConfigServiceName); // if a default MDB pool is already installed, then remove it first if (existingDefaultPoolConfigService != null) { context.removeService(existingDefaultPoolConfigService); } if (poolName.isDefined()) { // now install default pool config service which points to an existing pool config service final ValueInjectionService<PoolConfig> newDefaultPoolConfigService = new ValueInjectionService<PoolConfig>(); ServiceController<?> newController = context .getServiceTarget() .addService(poolConfigServiceName, newDefaultPoolConfigService) .addDependency( PoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName.asString()), PoolConfig.class, newDefaultPoolConfigService.getInjector()) .install(); } }
static ModelNode parseCustomLoadMetric(XMLExtendedStreamReader reader) throws XMLStreamException { final ModelNode load = new ModelNode(); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case CAPACITY: load.get(CAPACITY).set(value); break; case WEIGHT: load.get(WEIGHT).set(value); break; case CLASS: load.get(CLASS).set(value); break; default: unexpectedAttribute(reader, i); } } while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); switch (element) { case PROPERTY: final Property property = parseProperty(reader); load.get("property").add(property.getName(), property.getValue()); break; default: unexpectedElement(reader); } } return load; }
private static void validateResolveExpressionOnMaster(final ModelNode result) { System.out.println(result); ModelNode serverResult = result.get("server-groups", "main-server-group", "host", "master", "main-one"); Assert.assertTrue(serverResult.isDefined()); validateResolveExpressionOnServer(serverResult); }
@org.junit.Ignore("This fails for some mysterious reason - but this isn't a critical test") @Test @BMRule( name = "Test remove rollback operation", targetClass = "org.jboss.as.clustering.jgroups.subsystem.StackRemoveHandler", targetMethod = "performRuntime", targetLocation = "AT EXIT", action = "traceln(\"Injecting rollback fault via Byteman\");$1.setRollbackOnly()") public void testProtocolStackRemoveRollback() throws Exception { KernelServices services = buildKernelServices(); ModelNode operation = Operations.createCompositeOperation(addStackOp, addTransportOp, addProtocolOp); // add a protocol stack ModelNode result = services.executeOperation(operation); Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString()); // remove the protocol stack // the remove has OperationContext.setRollbackOnly() injected // and so is expected to fail result = services.executeOperation(removeStackOp); Assert.assertEquals(FAILED, result.get(OUTCOME).asString()); // need to check that all services are correctly re-installed ServiceName channelFactoryServiceName = ProtocolStackServiceName.CHANNEL_FACTORY.getServiceName("maximal2"); Assert.assertNotNull( "channel factory service not installed", services.getContainer().getService(channelFactoryServiceName)); }
/** * Execute an operation and wait until the connection is closed. This is only useful for :reload * and :shutdown operations. * * @param operation the operation to execute * @return the operation result * @throws IOException for any error */ public ModelNode executeAwaitConnectionClosed(final ModelNode operation) throws IOException { final DomainTestClient client = internalGetOrCreateClient(); final Channel channel = client.getChannel(); final Connection ref = channel.getConnection(); ModelNode result = new ModelNode(); try { result = client.execute(operation); // IN case the operation wasn't successful, don't bother waiting if (!"success".equals(result.get("outcome").asString())) { return result; } } catch (Exception e) { if (e instanceof IOException) { final Throwable cause = e.getCause(); if (cause instanceof ExecutionException) { // ignore, this might happen if the channel gets closed before we got the response } else { throw (IOException) e; } } else { throw new RuntimeException(e); } } try { if (channel != null) { // Wait for the channel to close channel.awaitClosed(); } // Wait for the connection to be closed connection.awaitConnectionClosed(ref); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return result; }
private ModelNode parseDatabaseBinaryStorage( final XMLExtendedStreamReader reader, final String repositoryName) throws XMLStreamException { final ModelNode storageType = new ModelNode(); storageType.get(OP).set(ADD); storageType .get(OP_ADDR) .add(SUBSYSTEM, ModeShapeExtension.SUBSYSTEM_NAME) .add(ModelKeys.REPOSITORY, repositoryName) .add(ModelKeys.CONFIGURATION, ModelKeys.BINARY_STORAGE) .add(ModelKeys.STORAGE_TYPE, ModelKeys.DB_BINARY_STORAGE); if (reader.getAttributeCount() > 0) { for (int i = 0; i < reader.getAttributeCount(); i++) { String attrName = reader.getAttributeLocalName(i); String attrValue = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(attrName); switch (attribute) { // The rest go on the ModelNode for the type ... case DATA_SOURCE_JNDI_NAME: ModelAttributes.DATA_SOURCE_JNDI_NAME.parseAndSetParameter( attrValue, storageType, reader); break; case MIN_VALUE_SIZE: ModelAttributes.MINIMUM_BINARY_SIZE.parseAndSetParameter( attrValue, storageType, reader); break; default: throw ParseUtils.unexpectedAttribute(reader, i); } } } requireNoElements(reader); return storageType; }
@Override public void handleRequest( final DataInput input, final ActiveOperation.ResultHandler<Void> resultHandler, final ManagementRequestContext<Void> context) throws IOException { byte param = input.readByte(); // If it failed if (param != DomainControllerProtocol.PARAM_OK) { final byte errorCode = input.readByte(); final String message = input.readUTF(); resultHandler.failed( new SlaveRegistrationException( SlaveRegistrationException.ErrorCode.parseCode(errorCode), message)); return; } final ModelNode extensions = new ModelNode(); extensions.readExternal(input); context.executeAsync( new ManagementRequestContext.AsyncTask<Void>() { @Override public void execute(ManagementRequestContext<Void> voidManagementRequestContext) throws Exception { // final ModelNode subsystems = resolveSubsystemVersions(extensions); channelHandler.executeRequest( context.getOperationId(), new RegisterSubsystemsRequest(subsystems)); } }); }
private void writeOptional( XMLExtendedStreamWriter writer, Attribute attribute, ModelNode model, String key) throws XMLStreamException { if (model.hasDefined(key)) { writer.writeAttribute(attribute.getLocalName(), model.get(key).asString()); } }
private void addInterfaces(Map<String, ModelNode> map, ModelNode iface) { if (iface.isDefined()) { for (Property prop : iface.asPropertyList()) { map.put(prop.getName(), prop.getValue()); } } }
/** * Apply the remote read domain model result. * * @param result the domain model result * @return whether it was applied successfully or not */ boolean applyDomainModel(ModelNode result) { if (!result.hasDefined(ModelDescriptionConstants.RESULT)) { return false; } final List<ModelNode> bootOperations = result.get(ModelDescriptionConstants.RESULT).asList(); return callback.applyDomainModel(bootOperations); }
protected void addPath(ModelControllerClient client, Outcome expectedOutcome, String... roles) throws IOException { ModelNode op = createOpNode(TEST_PATH, ADD); op.get(PATH).set("/"); configureRoles(op, roles); RbacUtil.executeOperation(client, op, expectedOutcome); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final PathElement element = address.getLastElement(); final String serverName = element.getValue(); final ModelNode subModel = context.readModel(PathAddress.EMPTY_ADDRESS); final boolean isStart; if (subModel.hasDefined(AUTO_START)) { isStart = subModel.get(AUTO_START).asBoolean(); } else { isStart = true; } ServerStatus status = serverInventory.determineServerStatus(serverName); if (status == ServerStatus.STOPPED) { status = isStart ? status : ServerStatus.DISABLED; } if (status != null) { context.getResult().set(status.toString()); context.completeStep(); } else { throw new OperationFailedException(new ModelNode().set("Failed to get server status")); } }
@Test public void testParseSubsystem_1_0() throws Exception { String subsystemXml = "<subsystem xmlns=\"urn:jboss:domain:jacorb:1.0\">" + " <orb name=\"JBoss\" print-version=\"off\">" + " <connection retries=\"5\" retry-interval=\"500\" client-timeout=\"0\" server-timeout=\"0\"/>" + " <naming root-context=\"JBoss/Naming/root\" export-corbaloc=\"on\"/>" + " </orb>" + " <poa monitoring=\"off\" queue-wait=\"on\" queue-min=\"10\" queue-max=\"100\">" + " <request-processors pool-size=\"10\" max-threads=\"32\"/>" + " </poa>" + " <interop sun=\"on\" comet=\"off\" chunk-custom-rmi-valuetypes=\"on\"/>" + " <security support-ssl=\"off\" use-domain-socket-factory=\"off\" use-domain-server-socket-factory=\"off\"/>" + " <property key=\"a\" value=\"va\"/>" + " <property key=\"b\" value=\"vb\"/>" + " <initializers>security,transactions</initializers>" + "</subsystem>"; List<ModelNode> operations = super.parse(subsystemXml); // check that we have the expected number of operations. Assert.assertEquals(1, operations.size()); // check that each operation has the correct content. ModelNode addSubsystem = operations.get(0); Assert.assertEquals(ADD, addSubsystem.get(OP).asString()); PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR)); Assert.assertEquals(1, addr.size()); PathElement element = addr.getElement(0); Assert.assertEquals(SUBSYSTEM, element.getKey()); Assert.assertEquals(JacORBExtension.SUBSYSTEM_NAME, element.getValue()); }
/** * [AS7-5850] Core queues created with ActiveMQ API does not create WildFly resources * * <p>For backwards compatibility if an operation is invoked on a queue that has no corresponding * resources, we forward the operation to the corresponding runtime-queue resource (which *does* * exist). * * @return true if the operation is forwarded to the corresponding runtime-queue resource, false * else. */ static boolean forwardToRuntimeQueue( OperationContext context, ModelNode operation, OperationStepHandler handler) { PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); // do not forward if the current operation is for a runtime-queue already: if (RUNTIME_QUEUE.equals(address.getLastElement().getKey())) { return false; } String queueName = address.getLastElement().getValue(); PathAddress activeMQPathAddress = MessagingServices.getActiveMQServerPathAddress(address); Resource serverResource = context.readResourceFromRoot(activeMQPathAddress); boolean hasChild = serverResource.hasChild(address.getLastElement()); if (hasChild) { return false; } else { // there is no registered queue resource, forward to the runtime-queue address instead ModelNode forwardOperation = operation.clone(); forwardOperation .get(ModelDescriptionConstants.OP_ADDR) .set(activeMQPathAddress.append(RUNTIME_QUEUE, queueName).toModelNode()); context.addStep(forwardOperation, handler, OperationContext.Stage.RUNTIME, true); return true; } }
private void parseClusteredCacheAttribute( XMLExtendedStreamReader reader, int index, Attribute attribute, String value, ModelNode cache) throws XMLStreamException { switch (attribute) { case MODE: { cache.get(ModelKeys.MODE).set(value); break; } case QUEUE_SIZE: { cache.get(ModelKeys.QUEUE_SIZE).set(Integer.parseInt(value)); break; } case QUEUE_FLUSH_INTERVAL: { cache.get(ModelKeys.QUEUE_FLUSH_INTERVAL).set(Long.parseLong(value)); break; } case REMOTE_TIMEOUT: { cache.get(ModelKeys.REMOTE_TIMEOUT).set(Long.parseLong(value)); break; } default: { this.parseCacheAttribute(reader, index, attribute, value, cache); } } }
private void startServers() { ModelNode addr = new ModelNode(); addr.add(HOST, hostControllerInfo.getLocalHostName()); ModelNode op = Util.getEmptyOperation(StartServersHandler.OPERATION_NAME, addr); getValue().execute(op, null, null, null); }
private void parseStateTransfer(XMLExtendedStreamReader reader, ModelNode stateTransfer) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { stateTransfer.get(ModelKeys.ENABLED).set(Boolean.parseBoolean(value)); break; } case TIMEOUT: { stateTransfer.get(ModelKeys.TIMEOUT).set(Long.parseLong(value)); break; } case FLUSH_TIMEOUT: { stateTransfer.get(ModelKeys.FLUSH_TIMEOUT).set(Long.parseLong(value)); break; } default: { throw ParseUtils.unexpectedAttribute(reader, i); } } } ParseUtils.requireNoContent(reader); }
private ModelNode readAttribute(String name, ModelNode address) { ModelNode op = new ModelNode(); op.get("operation").set("read-attribute"); op.get("address").set(address); op.get("name").set(name); return executeForResult(new OperationBuilder(op).build()); }
private void parseEviction(XMLExtendedStreamReader reader, ModelNode eviction) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case STRATEGY: { try { EvictionStrategy strategy = EvictionStrategy.valueOf(value); eviction.get(ModelKeys.STRATEGY).set(strategy.name()); } catch (IllegalArgumentException e) { throw ParseUtils.invalidAttributeValue(reader, i); } break; } case MAX_ENTRIES: { eviction.get(ModelKeys.MAX_ENTRIES).set(Integer.parseInt(value)); break; } case INTERVAL: { ROOT_LOGGER.deprecatedAttribute( attribute.getLocalName(), Element.EVICTION.getLocalName(), "ISPN-1268"); break; } default: { throw ParseUtils.unexpectedAttribute(reader, i); } } } ParseUtils.requireNoContent(reader); }
private void parseAuthenticator(final XMLExtendedStreamReader reader, final ModelNode repository) throws XMLStreamException { if (reader.getAttributeCount() > 0) { ModelNode authenticator = new ModelNode(); for (int i = 0; i < reader.getAttributeCount(); i++) { String attrName = reader.getAttributeLocalName(i); String attrValue = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(attrName); switch (attribute) { // Set these as properties on the repository ModelNode ... case NAME: ModelAttributes.NAME.parseAndSetParameter(attrValue, authenticator, reader); break; case CLASSNAME: ModelAttributes.CLASSNAME.parseAndSetParameter(attrValue, authenticator, reader); if (!authenticator.has(ModelKeys.NAME)) { ModelAttributes.NAME.parseAndSetParameter(attrValue, authenticator, reader); } break; case MODULE: ModelAttributes.MODULE.parseAndSetParameter(attrValue, authenticator, reader); break; default: authenticator.get(attrName).set(attrValue); break; } } if (authenticator.has(ModelKeys.NAME)) repository.get(ModelKeys.AUTHENTICATORS).add(authenticator); } requireNoElements(reader); }
private void parseExpiration(XMLExtendedStreamReader reader, ModelNode expiration) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case MAX_IDLE: { expiration.get(ModelKeys.MAX_IDLE).set(Long.parseLong(value)); break; } case LIFESPAN: { expiration.get(ModelKeys.LIFESPAN).set(Long.parseLong(value)); break; } case INTERVAL: { expiration.get(ModelKeys.INTERVAL).set(Long.parseLong(value)); break; } default: { throw ParseUtils.unexpectedAttribute(reader, i); } } } ParseUtils.requireNoContent(reader); }
static ModelNode getConnectorRemove(final Locale locale) { final ResourceBundle bundle = getResourceBundle(locale); final ModelNode node = new ModelNode(); node.get(OPERATION_NAME).set(REMOVE); node.get(DESCRIPTION).set(bundle.getString("web.connector.remove")); return node; }
private void parseFileStore(XMLExtendedStreamReader reader, ModelNode store) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case RELATIVE_TO: { store.get(ModelKeys.RELATIVE_TO).set(value); break; } case PATH: { store.get(ModelKeys.PATH).set(value); break; } default: { this.parseStoreAttribute(reader, i, attribute, value, store); } } } this.parseStoreProperties(reader, store); }
private ModelNode getAddSocketBindingOp(Connector conn, int port) { ModelNode op = createOpNode( "socket-binding-group=standard-sockets/socket-binding=test-" + conn.getName(), "add"); op.get("port").set(port); return op; }
@Override public void persist(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException { boolean wildcard = getPathElement().isWildcard(); model = wildcard ? model.get(getPathElement().getKey()) : model.get(getPathElement().getKeyValuePair()); if (!model.isDefined()) { return; } boolean writeWrapper = getXmlWrapperElement() != null; if (writeWrapper) { writer.writeStartElement(getXmlWrapperElement()); } writer.writeStartElement(getXmlElementName()); if (wildcard) { for (Property p : model.asPropertyList()) { writer.writeAttribute(NAME, p.getName()); for (AttributeDefinition def : getAttributes()) { def.getAttributeMarshaller().marshallAsAttribute(def, p.getValue(), false, writer); } persistChildren(writer, p.getValue()); } } else { for (AttributeDefinition def : getAttributes()) { def.getAttributeMarshaller().marshallAsAttribute(def, model, false, writer); } persistChildren(writer, model); } writer.writeEndElement(); if (writeWrapper) { writer.writeEndElement(); } }
static ModelNode parseModClusterConfig(XMLExtendedStreamReader reader) throws XMLStreamException { final ModelNode config = new ModelNode(); // Parse the attributes. parsePropConf(reader, config); // Parse the elements while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); switch (element) { case SIMPLE_LOAD_PROVIDER: final ModelNode load = parseSimpleLoadProvider(reader); config.get(SIMPLE_LOAD_PROVIDER).set(load); break; case DYNAMIC_LOAD_PROVIDER: final ModelNode dynload = parseDynamicLoadProvider(reader); config.get(DYNAMIC_LOAD_PROVIDER).set(dynload); break; case SSL: final ModelNode ssl = parseSSL(reader); config.get(SSL).set(ssl); break; default: unexpectedElement(reader); } } return config; }
protected List<ModelNode> readFile(File file, int expectedRecords) throws IOException { List<ModelNode> list = new ArrayList<ModelNode>(); final BufferedReader reader = new BufferedReader(new FileReader(file)); try { StringWriter writer = null; String line = reader.readLine(); while (line != null) { if (DATE_STAMP_PATTERN.matcher(line).find()) { if (writer != null) { list.add(ModelNode.fromJSONString(writer.getBuffer().toString())); } writer = new StringWriter(); writer.append("{"); } else { if (writer != null) writer.append("\n" + line); } line = reader.readLine(); } if (writer != null) { list.add(ModelNode.fromJSONString(writer.getBuffer().toString())); } } finally { IoUtils.safeClose(reader); } Assert.assertEquals(list.toString(), expectedRecords, list.size()); return list; }
static void writeAttribute( final XMLExtendedStreamWriter writer, final String name, ModelNode node) throws XMLStreamException { if (node.hasDefined(name)) { writer.writeAttribute(name, node.get(name).asString()); } }
private ModelNode loadDomainModel(File file) throws Exception { final QName rootElement = new QName(Namespace.CURRENT.getUriString(), "domain"); final DomainXml parser = new DomainXml(Module.getBootModuleLoader()); final XmlConfigurationPersister persister = new XmlConfigurationPersister(file, rootElement, parser, parser); final List<ModelNode> ops = persister.load(); final ModelNode model = new ModelNode(); final ModelController controller = createController( model, new Setup() { public void setup( Resource resource, ManagementResourceRegistration rootRegistration) { DomainModelUtil.updateCoreModel(resource.getModel()); DomainModelUtil.initializeMasterDomainRegistry( rootRegistration, persister, null, new MockFileRepository(), null, null); } }); final ModelNode caputreModelOp = new ModelNode(); caputreModelOp.get(OP_ADDR).set(PathAddress.EMPTY_ADDRESS.toModelNode()); caputreModelOp.get(OP).set("capture-model"); final List<ModelNode> toRun = new ArrayList<ModelNode>(ops); toRun.add(caputreModelOp); executeOperations(controller, toRun); // persister.store(model, null).commit(); return model; }